1

I have a model(I have omitted getters and setters for brevity) that looks like this:

public class ObjkeyInputPayloadItem {
    private String TYPE;
    private String BALL_NAME;
    private String TABLENAME;
    private String PARAMTYPE;
    private String FIELDNAME;
    private String FIELDVALUE;
}

I would like to convert it to json using ObjectMapper in jackson API:

String payloadStr = null;
try {
    payloadStr = mapper.writeValueAsString(payload);
} catch (JsonGenerationException e) {
    e.printStackTrace();
} catch (JsonMappingException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

I use the payloadStr as a camel cased string, how can I tell the ObjectMapper to use my bean's properties as they are without converting them.

4

1 回答 1

0

You can use the JsonProperty annotation on a field to override the name used:

@JsonProperty("ballName");
private String BALL_NAME;
于 2016-03-05T04:45:10.460 回答