コード例 #1
0
  @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));
  }
コード例 #2
0
  @Test
  public void testMarshalWithEmptyOption() {
    Map<String, String> options = Maps.newHashMap();

    String result = serializer.marshal(new MessageDto("hello"), options);
    assertThat(result, is(json));
  }
コード例 #3
0
  @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));
  }
コード例 #4
0
  @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\"]"));
  }
コード例 #5
0
  @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\"}"));
  }
コード例 #6
0
 @Test
 public void testUnmarshal() {
   MessageDto message = serializer.unmarshal(MessageDto.class, json);
   assertThat(message.message, is("hello"));
 }
コード例 #7
0
 @Test
 public void testMarshal() {
   String result = serializer.marshal(new MessageDto("hello"));
   assertThat(result, is(json));
 }