Specifying the field naming policy for Jackson

Now CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES is the deprecated strategy use SNAKE_CASE instead

ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(
    PropertyNamingStrategy.SNAKE_CASE);
mapper.writeValue(outStream, bean);

And yes I found it (it turned out that after 2 hours of searching I had been only 30 minutes away from finding it):

ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(
    PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
mapper.writeValue(outStream, bean);

Hopefully this will turn out to be helpful to somebody else too.

Tags:

Java

Json

Jackson