I have a Java object represented as JSON and I want to add additional fields to the JSON. I don't want to add these fields to the Java model, I just need to add them to the JSON before it is processed.
Here is a simplified version of what I have at the moment:
public void addAdditionalFields(JsonNode myObjectAsJsonNode) {
JsonFactory jsonFactory = new JsonFactory();
JsonGenerator jgen = jsonFactory.createJsonGenerator(new StringWriter());
jgen.writeStartObject();
jgen.writeObjectField("test", "myFieldsValue");
jgen.writeEndObject();
jacksonObjectMapper.writeTree(jgen, myObjectAsJsonNode);
}
The new field isn't added to the myObjectAsJsonNode
object.