use of com.baeldung.jackson.entities.Movie in project tutorials by eugenp.
the class JacksonDeserializeUnitTest method whenSimpleDeserialize_thenCorrect.
@Test
public void whenSimpleDeserialize_thenCorrect() throws IOException {
final String jsonInput = "{\"imdbId\":\"tt0472043\",\"actors\":[{\"imdbId\":\"nm2199632\",\"dateOfBirth\":\"1982-09-21T12:00:00+01:00\",\"filmography\":[\"Apocalypto\",\"Beatdown\",\"Wind Walkers\"]}]}";
final ObjectMapper mapper = new ObjectMapper();
final Movie movie = mapper.readValue(jsonInput, Movie.class);
final String expectedOutput = "Movie [imdbId=tt0472043, director=null, actors=[ActorJackson [imdbId=nm2199632, dateOfBirth=Tue Sep 21 11:00:00 GMT 1982, filmography=[Apocalypto, Beatdown, Wind Walkers]]]]";
assertEquals(expectedOutput, movie.toString());
}
use of com.baeldung.jackson.entities.Movie in project tutorials by eugenp.
the class JacksonDeserializeUnitTest method whenCustomDeserialize_thenCorrect.
@Test
public void whenCustomDeserialize_thenCorrect() throws IOException {
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: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 11:00:00 GMT 1982, filmography=[Apocalypto, Beatdown, Wind Walkers]]]]";
assertEquals(expectedOutput, movie.toString());
}
use of com.baeldung.jackson.entities.Movie in project tutorials by eugenp.
the class JacksonSerializeUnitTest method whenSimpleSerialize_thenCorrect.
@Test
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));
final ObjectMapper mapper = new ObjectMapper();
final String jsonResult = mapper.writeValueAsString(movie);
final String expectedOutput = "{\"imdbId\":\"tt0472043\",\"director\":\"Mel Gibson\",\"actors\":[{\"imdbId\":\"nm2199632\",\"dateOfBirth\":401414400000,\"filmography\":[\"Apocalypto\",\"Beatdown\",\"Wind Walkers\"]}]}";
Assert.assertEquals(jsonResult, expectedOutput);
}
Aggregations