• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind;
2 
3 import com.fasterxml.jackson.databind.testutil.MediaItem;
4 
5 public class RoundtripTest extends BaseMapTest
6 {
7     private final ObjectMapper MAPPER = new ObjectMapper();
8 
testMedaItemRoundtrip()9     public void testMedaItemRoundtrip() throws Exception
10     {
11         MediaItem.Content c = new MediaItem.Content();
12         c.setBitrate(9600);
13         c.setCopyright("none");
14         c.setDuration(360000L);
15         c.setFormat("lzf");
16         c.setHeight(640);
17         c.setSize(128000L);
18         c.setTitle("Amazing Stuff For Something Or Oth\u00CBr!");
19         c.setUri("http://multi.fario.us/index.html");
20         c.setWidth(1400);
21 
22         c.addPerson("Joe Sixp\u00e2ck");
23         c.addPerson("Ezekiel");
24         c.addPerson("Sponge-Bob Squarepant\u00DF");
25 
26         MediaItem input = new MediaItem(c);
27         input.addPhoto(new MediaItem.Photo());
28         input.addPhoto(new MediaItem.Photo());
29         input.addPhoto(new MediaItem.Photo());
30 
31         String json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(input);
32 
33         MediaItem output = MAPPER.readValue(new java.io.StringReader(json), MediaItem.class);
34         assertNotNull(output);
35 
36         assertNotNull(output.getImages());
37         assertEquals(input.getImages().size(), output.getImages().size());
38         assertNotNull(output.getContent());
39         assertEquals(input.getContent().getTitle(), output.getContent().getTitle());
40         assertEquals(input.getContent().getUri(), output.getContent().getUri());
41 
42         // compare re-serialization as a simple check as well
43         assertEquals(json, MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(output));
44     }
45 }
46