onkami
onkami

Reputation: 9411

Jackson: marshal to JSON with UpperCamelCase

I have a POJO object that has UpperCamelCase naming. When I do the call to Jackson's ObjectMapper to serialize/marshal it to JSON, the result is lowerCamelCase for field names.

The call is now trivial:

Heading

ObjectMapper objectMapper = new ObjectMapper();
jsonText = objectMapper.writeValueAsString(myObjectToJson);

how I can tell ObjectMapper to make UpperCamelCase? Or is it some sort of set-in-stone JSON standard?

I use jackson inside Apache Camel.

Upvotes: 2

Views: 1193

Answers (1)

Martin Hansen
Martin Hansen

Reputation: 2101

edited original answer.

Jackson uses camelCasing as default it seems. They have implemented a PascalCasing strategy. Try this:

ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.PASCAL_CASE_TO_CAMEL_CASE);

Or annotate your fields with @JsonProperty("UpperCaseProperty")

Upvotes: 2

Related Questions