Exemple #1
0
  @Test
  public void Conversions_toMap_DoesNotAllowReplacement() {
    ObjectMapper o = new ObjectMapperImpl();

    Stuffing stuffing = new Stuffing();
    stuffing.name = "i'm Stuffed!";
    stuffing.stuff = Stuff.THIS_KIND_OF_STUFF;

    stuffing.stuffed = new Stuffing.Stuffed();
    stuffing.stuffed.dateStuffed = new Date();

    // Make it a string to start with. (pretend this is JSON coming over the wire as a string, for
    // example
    String jsonVersion = o.toJson(stuffing);

    // Now lets make it a map to grab stuff and change stuff
    Map<String, Object> requestObject = o.fromJson(jsonVersion, Map.class);

    puts("Before", requestObject);

    /* It is not a real map. It is a facade over a index overlay. */

    requestObject = new HashMap<>(requestObject);

    Map<String, Object> stuffed = new HashMap<>((Map<String, Object>) requestObject.get("stuffed"));
    stuffed.put("dateStuffed", System.currentTimeMillis());
    stuffed.put("bacon", "yummy");

    requestObject.put("stuffed", stuffed);

    puts("After", requestObject);
  }
Exemple #2
0
 @Override
 public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
   BufferedWriter writer =
       IOHelper.buffered(new OutputStreamWriter(stream, IOHelper.getCharsetName(exchange)));
   objectMapper.toJson(graph, writer);
   writer.close();
 }