Jackson field value with no quotation marks Jackson field value with no quotation marks json json

Jackson field value with no quotation marks


As others have pointed out, double-quotes are not optional in JSON, but mandatory.

Having said that, you can use annotation JsonRawValue to do what you want.

public class POJO {  public String name;  @JsonRawValue  public String click;}


Well, technicaly you can do it. Although the result would not be a valid JSON, it is still possible with Jackson:

class Dto  {    @JsonProperty("name")    String foo = "nameValue";    @JsonProperty("click")    JsEntry entry = new JsEntry("function (e){console.log(\"message\");}");}class JsEntry implements JsonSerializableWithType {    private String value;    JsEntry(String value) {        this.value = value;    }    @Override    public void serializeWithType(JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException {        this.serialize(jgen, provider);    }    @Override    public void serialize(JsonGenerator jgen, SerializerProvider provider) throws IOException {        jgen.writeRawValue(value);    }}

I'm fully agree, however, that this requirement causes a standard violation and should be revised.


That's not valid JSON, so you can't have it. JSON is a value transfer format, so you can't transfer functions.

If you really need to return functions in JSON, you can probably post-process the result in javascript.