From 008e340482d77a0a1329dd49b56c9e9acd199e40 Mon Sep 17 00:00:00 2001 From: Amitabh Tiwari Date: Fri, 15 Oct 2021 19:25:52 +0530 Subject: [PATCH] Update SerializationUtils.java Updating serialization Utils --- .../java/com/baeldung/util/SerializationUtils.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/util/SerializationUtils.java b/core-java-modules/core-java/src/main/java/com/baeldung/util/SerializationUtils.java index 7ebff1a113..429325eb43 100644 --- a/core-java-modules/core-java/src/main/java/com/baeldung/util/SerializationUtils.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/util/SerializationUtils.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.lang.reflect.Field; public class SerializationUtils { @@ -26,6 +27,15 @@ public class SerializationUtils { } public static boolean isSerializable(Class it) { - return it.isPrimitive() || it.isInterface() || Serializable.class.isAssignableFrom(it); + boolean serializable = it.isPrimitive() || it.isInterface() || Serializable.class.isAssignableFrom(it); + if(!serializable) { + return serializable; + } + Field[] declaredFields = it.getDeclaredFields(); + for(Field field: declaredFields) { + Class fieldType = field.getType(); + return isSerializable(fieldType); + } + return serializable; } }