@Test public void testMarshalAndUnmarshalWithDateTimeGetter() { DateTime dateTime = ISODateTimeFormat.dateTimeParser() .withOffsetParsed() .parseDateTime("2013-07-10T15:37:58.340+02:00"); ClassWithDateTimeGetter myObject = new ClassWithDateTimeGetter(dateTime); String marshaled = serializer.marshal(myObject); assertThat(marshaled, is("{\"dateTime\":\"2013-07-10T15:37:58.340+02:00\"}")); ClassWithDateTimeGetter unmarshaled = serializer.unmarshal(ClassWithDateTimeGetter.class, marshaled); assertThat(unmarshaled, equalTo(myObject)); }
@Test public void testMarshalWithEmptyOption() { Map<String, String> options = Maps.newHashMap(); String result = serializer.marshal(new MessageDto("hello"), options); assertThat(result, is(json)); }
@Test public void testMarshalWithCallbackOption() { Map<String, String> options = Maps.newHashMap(); options.put("callback", "test"); String result = serializer.marshal(new MessageDto("hello"), options); assertThat(result, is(jsonp)); }
@Test public void testMarshalList() { List<String> contentList = new ArrayList<String>(); contentList.add("one"); contentList.add("two"); contentList.add("three"); Map<String, String> options = Maps.newHashMap(); String marshaled = serializer.marshal(contentList, options); assertThat(marshaled, is("[\"one\",\"two\",\"three\"]")); }
@Test public void testMarshalMap() { Map<String, Object> map = new HashMap<String, Object>(); map.put("message", "hello"); List<String> contentList = new ArrayList<String>(); contentList.add("one"); contentList.add("two"); contentList.add("three"); map.put("content", contentList); Map<String, String> options = Maps.newHashMap(); String marshaled = serializer.marshal(map, options); assertThat(marshaled, is("{\"content\":[\"one\",\"two\",\"three\"],\"message\":\"hello\"}")); }
@Test public void testUnmarshal() { MessageDto message = serializer.unmarshal(MessageDto.class, json); assertThat(message.message, is("hello")); }
@Test public void testMarshal() { String result = serializer.marshal(new MessageDto("hello")); assertThat(result, is(json)); }