I have the following code using the JSON Processing API (descriptor is the interface I'm trying to serialize).
public void serialize(ComponentDescriptor descriptor, JsonGenerator generator, SerializationContext ctx) {
generator.writeStartObject();
generator.writeStartObject(descriptor.getClass().getName());
generator.write("name", descriptor.getName());
ctx.serialize("settings", descriptor.getSettings(), generator);
generator.writeEnd();
generator.writeEnd();
}
This works fine with Yasson, but if I try to serialize the same object with Johnzon I get:
javax.json.stream.JsonGenerationException: state START_OBJECT does not accept a value
There's clearly a difference between the two implementations (which I'm guessing there shouldn't be), but what is the correct way to write my object (ideally so it works in both)?
The sort of output I'm expecting is:
{
"my.package.TestDescriptor": {
"name": "Test",
"settings": {
"host": "localhost",
"port":8080
}
}
}