예제 #1
0
  public void testCalendarMap() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(123456000L);
    DateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
    String JSON =
        "{ \"" + fmt.format(c.getTime()) + "\" : \"\", \"" + new Date(0).getTime() + "\" : null }";
    HashMap<Calendar, String> result =
        mapper.readValue(JSON, new TypeReference<HashMap<Calendar, String>>() {});

    assertNotNull(result);
    assertEquals(HashMap.class, result.getClass());
    assertEquals(2, result.size());

    assertTrue(result.containsKey(c));
    assertEquals("", result.get(c));
    c.setTimeInMillis(0);
    assertTrue(result.containsKey(c));
    assertNull(result.get(c));
  }
예제 #2
0
  public void testDateMap() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    Date date1 = new Date(123456000L);
    DateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");

    String JSON =
        "{ \"" + fmt.format(date1) + "\" : \"\", \"" + new Date(0).getTime() + "\" : null }";
    HashMap<Date, String> result =
        mapper.readValue(JSON, new TypeReference<HashMap<Date, String>>() {});

    assertNotNull(result);
    assertEquals(HashMap.class, result.getClass());
    assertEquals(2, result.size());

    assertTrue(result.containsKey(date1));
    assertEquals("", result.get(new Date(123456000L)));

    assertTrue(result.containsKey(new Date(0)));
    assertNull(result.get(new Date(0)));
  }