diff --git a/gson/src/test/java/org/baeldung/gson/serialization/IgnoringFieldsSerializer.java b/gson/src/test/java/org/baeldung/gson/serialization/IgnoringFieldsSerializer.java index c8fb95028c..bd1928cb18 100644 --- a/gson/src/test/java/org/baeldung/gson/serialization/IgnoringFieldsSerializer.java +++ b/gson/src/test/java/org/baeldung/gson/serialization/IgnoringFieldsSerializer.java @@ -16,5 +16,4 @@ public class IgnoringFieldsSerializer implements JsonSerializer { return jObject; } - } diff --git a/gson/src/test/java/org/baeldung/gson/serialization/test/GsonSerializationTest.java b/gson/src/test/java/org/baeldung/gson/serialization/test/GsonSerializationTest.java index fe19efdb45..3e957ea6f8 100644 --- a/gson/src/test/java/org/baeldung/gson/serialization/test/GsonSerializationTest.java +++ b/gson/src/test/java/org/baeldung/gson/serialization/test/GsonSerializationTest.java @@ -33,9 +33,7 @@ public class GsonSerializationTest { @Test public void givenCollection_whenSerializing_thenCorrect() { final Collection sourceCollection = Lists.newArrayList(new SourceClass(1, "one"), new SourceClass(2, "two")); - final Type sourceCollectionType = new TypeToken>() { - }.getType(); - final String jsonCollection = new Gson().toJson(sourceCollection, sourceCollectionType); + final String jsonCollection = new Gson().toJson(sourceCollection); final String expectedResult = "[{\"intValue\":1,\"stringValue\":\"one\"},{\"intValue\":2,\"stringValue\":\"two\"}]"; assertEquals(expectedResult, jsonCollection); @@ -63,19 +61,6 @@ public class GsonSerializationTest { assertEquals(expectedResult, jsonString); } - @Test - public void givenDate_whenSerializing_thenCorrect() { - final Date sourceDate = new Date(1000000L); - final Gson gson = new Gson(); - final Type sourceDateType = new TypeToken() { - }.getType(); - String jsonDate = gson.toJson(sourceDate, sourceDateType); - - System.out.println("jsonDate:\n" + jsonDate); - final String expectedResult = "\"Jan 1, 1970 3:16:40 AM\""; - assertTrue(jsonDate.equals(expectedResult)); - } - @Test public void givenUsingCustomDeserializer_whenFieldNotMatchesCriteria_thenIgnored() { final SourceClass sourceObject = new SourceClass(-1, "minus 1"); @@ -84,10 +69,23 @@ public class GsonSerializationTest { final Gson gson = gsonBuildr.create(); final Type sourceObjectType = new TypeToken() { }.getType(); - String jsonString = gson.toJson(sourceObject, sourceObjectType); + final String jsonString = gson.toJson(sourceObject, sourceObjectType); final String expectedResult = "{\"stringValue\":\"minus 1\"}"; assertEquals(expectedResult, jsonString); } + @Test + public void givenDate_whenSerializing_thenCorrect() { + final Date sourceDate = new Date(1000000L); + final Gson gson = new Gson(); + final Type sourceDateType = new TypeToken() { + }.getType(); + final String jsonDate = gson.toJson(sourceDate, sourceDateType); + + System.out.println("jsonDate:\n" + jsonDate); + final String expectedResult = "\"Jan 1, 1970 3:16:40 AM\""; + assertTrue(jsonDate.equals(expectedResult)); + } + } \ No newline at end of file diff --git a/jackson/src/test/java/org/baeldung/gson/GenericSourceClass.java b/jackson/src/test/java/org/baeldung/gson/GenericSourceClass.java deleted file mode 100644 index 8e3a8d749b..0000000000 --- a/jackson/src/test/java/org/baeldung/gson/GenericSourceClass.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.baeldung.gson; - -public class GenericSourceClass { - int intField; - - public GenericSourceClass(final int i) { - intField = i; - } - -} \ No newline at end of file diff --git a/jackson/src/test/java/org/baeldung/gson/GsonDeserializationUnitTest.java b/jackson/src/test/java/org/baeldung/gson/GsonDeserializationUnitTest.java deleted file mode 100644 index dabc861ce1..0000000000 --- a/jackson/src/test/java/org/baeldung/gson/GsonDeserializationUnitTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.baeldung.gson; - -import org.junit.Before; -import org.junit.Test; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; - -public class GsonDeserializationUnitTest { - - private Gson gson; - - @Before - public final void before() { - gson = new Gson(); - } - - // tests - - @Test - public void givenUsingGson_whenDeserializingGeneric_thenCorrect() { - final java.lang.reflect.Type genericSourceClassType = new TypeToken() { - }.getType(); - final GenericSourceClass sourceObject = new GenericSourceClass(1); - final String serializedSourceObject = gson.toJson(sourceObject, genericSourceClassType); - - final GenericSourceClass targetObject = gson.fromJson(serializedSourceObject, genericSourceClassType); - - System.out.println(targetObject); - } - -}