@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); }
@Override public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { BufferedReader reader = IOHelper.buffered(new InputStreamReader(stream, IOHelper.getCharsetName(exchange))); Object result = objectMapper.fromJson(reader, this.unmarshalType); reader.close(); return result; }