/**
   * Let's also try another way to express "gimme a Map" deserialization; this time by specifying a
   * Map class, to reduce need to cast
   */
  public void testUntypedMap2() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    // to get "untyped" default map-to-map, pass Object.class
    String JSON = "{ \"a\" : \"x\" }";

    @SuppressWarnings("unchecked")
    HashMap<String, Object> result = /*(HashMap<String,Object>)*/
        mapper.readValue(JSON, HashMap.class);
    assertNotNull(result);
    assertTrue(result instanceof Map<?, ?>);

    assertEquals(1, result.size());

    assertEquals("x", result.get("a"));
  }
  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));
  }
  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)));
  }
Example #4
0
 /** Clears the flash scope. */
 @Override
 public void clear() {
   isDirty = true;
   super.clear();
 }
Example #5
0
 /** Adds the given values to the flash scope. */
 @Override
 public void putAll(Map<? extends String, ? extends String> values) {
   isDirty = true;
   super.putAll(values);
 }