I am trying to learn the Jackson library for parsing Json in Java, and I am becoming more and more frustrated. It does not seem like this library will recognize any getters and setters that do not follow the typical Java Bean naming convention.
Using the ObjectMapper to create Java objects from Json strings or Json strings from Java object works fine as long as I stick to this naming convention.
However I am used to avoid prefixing getters with ‘get’, and instead giving the getter method the same name that the field that it is retrieving has.
How do I make the ObjectMapper able to serialize/deserialize objects that have custom names it’s getter methods?
I tried to create a custom PropertyNamingStrategy and applying it to a ObjectMapper instance, following this guide, but this did not work at all.
I tried to annotate the getter methods with @JsonProperty(“field name
“), which works – but adds a lot of ugly code to the class which is not a viable option on my opinion.
Using the JsonAutoDetect annotation doesn’t work either.
https://dzone.com/articles/jackson-property-custom-naming-strategy