diff --git a/jackson/src/test/java/org/baeldung/jackson/deserialization/JacksonDeserializeTest.java b/jackson/src/test/java/org/baeldung/jackson/deserialization/JacksonDeserializeTest.java index 31a6ae8ef9..503b6eb99b 100644 --- a/jackson/src/test/java/org/baeldung/jackson/deserialization/JacksonDeserializeTest.java +++ b/jackson/src/test/java/org/baeldung/jackson/deserialization/JacksonDeserializeTest.java @@ -29,12 +29,12 @@ public class JacksonDeserializeTest { final String jsonInput = "{\"imdbId\":\"tt0472043\",\"director\":\"Mel Gibson\",\"actors\":[{\"imdbId\":\"nm2199632\",\"dateOfBirth\":\"1982-09-21T12:00:00+01:00\",\"filmography\":[\"Apocalypto\",\"Beatdown\",\"Wind Walkers\"]}]}"; final ObjectMapper mapper = new ObjectMapper(); - final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); mapper.setDateFormat(df); final Movie movie = mapper.readValue(jsonInput, Movie.class); - final String expectedOutput = "Movie [imdbId=tt0472043, director=Mel Gibson, actors=[ActorJackson [imdbId=nm2199632, dateOfBirth=Tue Sep 21 09:00:00 GMT 1982, filmography=[Apocalypto, Beatdown, Wind Walkers]]]]"; + final String expectedOutput = "Movie [imdbId=tt0472043, director=Mel Gibson, actors=[ActorJackson [imdbId=nm2199632, dateOfBirth=Tue Sep 21 11:00:00 GMT 1982, filmography=[Apocalypto, Beatdown, Wind Walkers]]]]"; Assert.assertEquals(movie.toString(), expectedOutput); } diff --git a/jackson/src/test/java/org/baeldung/jackson/serialization/JacksonSerializeTest.java b/jackson/src/test/java/org/baeldung/jackson/serialization/JacksonSerializeTest.java index fcf19fcfad..6d9e378025 100644 --- a/jackson/src/test/java/org/baeldung/jackson/serialization/JacksonSerializeTest.java +++ b/jackson/src/test/java/org/baeldung/jackson/serialization/JacksonSerializeTest.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.TimeZone; import org.baeldung.jackson.entities.ActorJackson; import org.baeldung.jackson.entities.Movie; @@ -23,6 +24,7 @@ public class JacksonSerializeTest { public void whenSimpleSerialize_thenCorrect() throws JsonProcessingException, ParseException { final SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); + sdf.setTimeZone(TimeZone.getTimeZone("GMT")); final ActorJackson rudyYoungblood = new ActorJackson("nm2199632", sdf.parse("21-09-1982"), Arrays.asList("Apocalypto", "Beatdown", "Wind Walkers")); final Movie movie = new Movie("tt0472043", "Mel Gibson", Arrays.asList(rudyYoungblood)); @@ -30,7 +32,7 @@ public class JacksonSerializeTest { final ObjectMapper mapper = new ObjectMapper(); final String jsonResult = mapper.writeValueAsString(movie); - final String expectedOutput = "{\"imdbId\":\"tt0472043\",\"director\":\"Mel Gibson\",\"actors\":[{\"imdbId\":\"nm2199632\",\"dateOfBirth\":401403600000,\"filmography\":[\"Apocalypto\",\"Beatdown\",\"Wind Walkers\"]}]}"; + final String expectedOutput = "{\"imdbId\":\"tt0472043\",\"director\":\"Mel Gibson\",\"actors\":[{\"imdbId\":\"nm2199632\",\"dateOfBirth\":401414400000,\"filmography\":[\"Apocalypto\",\"Beatdown\",\"Wind Walkers\"]}]}"; Assert.assertEquals(jsonResult, expectedOutput); }