pretty print not working with custom serializer?
darmbrust opened this issue · comments
If I set up for write like so:
Map<String, Object> args = new HashMap<>();
args.put(JsonWriter.PRETTY_PRINT, true);
json_ = new JsonWriter(new FileOutputStream(path.toFile()), args);
json_.addWriter(ConceptChronology.class, new Writers.ConceptChronologyJsonWriter());
and my custom writer looks like this:
public static class ConceptChronologyJsonWriter implements JsonWriter.JsonClassWriter
{
public void write(Object obj, boolean showType, Writer output) throws IOException
{
ConceptChronology cc = (ConceptChronology) obj;
output.write("\"primordialUuid\":\"");
output.write(cc.getPrimordialUuid().toString());
output.write("\"");
output.write(",\"conceptSequence\":\"");
output.write(cc.getConceptSequence() + "");
output.write("\"");
}
The output ends up looking like this:
{
"@type":"gov.vha.isaac.ochre.model.concept.ConceptChronologyImpl",
"primordialUuid":"1f201994-960e-11e5-8994-feff819cdc9f","conceptSequence":"1"
}
I would expect a line return between the two variables.
I can't add the line return myself, because I don't know how much to indent.
I guess this doesn't really work like I thought it might.
I see I can get closer to what I want by implementing JsonClassWriterEx instead of JsonClassWriter, which will give me a handle to the underlying JsonWriter like so:
JsonWriter mainWriter = Support.getWriter(args);
But then, we still need to change the signature of methods like newLine() and tabIn() and tabOut() to public in order to do line returns properly.