Skip to content

Static encoder codegen with Any #145

@nedtwigg

Description

@nedtwigg

For jsoniter 0.9.19, with this class:

public class EmailSelf {
	public String subject;
	public String body;
	public Any cidMap;
}

jsoniter codegen generates this:

public class EmailSelf implements com.jsoniter.spi.Encoder {
public void encode(java.lang.Object obj, com.jsoniter.output.JsonStream stream) throws java.io.IOException {
if (obj == null) { stream.writeNull(); return; }
stream.writeRaw("{\"subject\":", 11);
encode_((java2ts.EmailSelf)obj, stream);
stream.write((byte)'}');
}
public static void encode_(java2ts.EmailSelf obj, com.jsoniter.output.JsonStream stream) throws java.io.IOException {
if (obj.subject == null) { stream.writeNull(); } else {
stream.writeVal((java.lang.String)obj.subject);
}
stream.writeRaw(",\"body\":", 8);
if (obj.body == null) { stream.writeNull(); } else {
stream.writeVal((java.lang.String)obj.body);
}
stream.writeRaw(",\"cidMap\":", 10);
if (obj.cidMap == null) { stream.writeNull(); } else {
stream.write((byte)'{', (byte)'}');
jsoniter_codegen.cfg9223372036100299902.encoder.com.jsoniter.any.Any.encode_((com.jsoniter.any.Any)obj.cidMap, stream);

}
}

The problem is if (obj.cidMap == null) { stream.writeNull(); } else { stream.write((byte)'{', (byte)'}');. No matter what value is assigned to cid, it shows up as cid: {} in the generated json. This isn't a problem when the same code is used in dynamic mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions