I'm generating JSON using Jackson's JsonGenerator, and would like to insert a child object from a literal JSON string.
gen.writeStartObject();
gen.writeStringField("name", "john");
gen.writeFieldName("profile");
gen.writeRaw(profilestring);
gen.writeEndObject();
This results in
Could not write content: Can not write a field name, expecting a value; nested exception is com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
Any thoughts?
Update: solved using
gen.writeRaw(",\"profile\":" + profilestring);
Use writeRawValue rather than writeRaw to make the generator output the right punctuation and update its state (tested with 2.5.3):