2

I am using https://immutables.github.io/ library with Jackson. I want my class to be Jackson-serializable. I would like to use custom PropertyNamingStrategy (configured for com.fasterxml.jackson.databind.ObjectMapper using mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);

Unfortunately Immutables library puts @JsonProperty("propertyName") at every field in generated code. That overrides PropertyNamingStrategy defined at mapper level (or at class level, using @com.fasterxml.jackson.databind.annotation.JsonNaming annotation).

Is it possible to make Immutables library stop putting property name for every field (using org.immutables.value.Value.Style or similar means)?

I have come with workaround, putting @JsonProperty (without value) at every property, but I am not satisfied with this.

Bartosz Bilicki
  • 12,599
  • 13
  • 71
  • 113

1 Answers1

3

Style property forceJacksonPropertyNames=false does not force property names to specific strings. It works with naming strategies configured at class level and at mapper level.

Introduction to styles is available here: http://immutables.github.io/style.html

You can read some background information about this setting in issues: https://github.com/immutables/immutables/issues/431 https://github.com/immutables/immutables/issues/353

Bartosz Bilicki
  • 12,599
  • 13
  • 71
  • 113
Ievgen Lukash
  • 390
  • 2
  • 7
  • Thanks! forceJacksonPropertyNames = false indeed has the result that generated Immutable* class has JsonProperty annotations without name. That causes Jackson to respect naming strategy of my com.fasterxml.jackson.databind.ObjectWriter, or naming strategy set by @JsonNaming on class level. It would be great to have forceJacksonPropertyNames documeted on http://immutables.github.io/style.html page. Currently it is not mentioned on that page, and whole org.immutables.value.Value.Style is not docummented in javadoc. – Bartosz Bilicki Oct 10 '16 at 08:28
  • It's hard to keep documentation page and Javadoc in sync, so they have different roles: the page serves as an introduction to styles, where Javadoc is a detailed (as much as it tries) reference. Sorry if that's less transparent that it should be, we'll try to improve this! Thank you! – Ievgen Lukash Oct 10 '16 at 21:47