I found this method in the code:
private MessageConverter makeJsonConverter() {
var jsonConverter = new MappingJackson2MessageConverter();
var mapper = jsonConverter.getObjectMapper();
mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
return jsonConverter;
}
Can anyone explain me the meaning of mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES)) ? How do we change the behaviour of mapping here? What will be different if we compare it with the default ObjectMapper?
The best and up to date answer for this question you can find on the GitHub page for this module: jackson-modules-java8/parameter-names.
Main goal:
Delegating creator:
To understand it a little bit better we need to create a simple
POJOand log what is invoked when. Take a look at below class:For different modes app prints different results.
JsonCreator.Mode.DEFAULT:JsonCreator.Mode.DISABLED:JsonCreator.Mode.DELEGATING:JsonCreator.Mode.PROPERTIES:Now, let's add extra method to our
POJOand change mode for 2-arg constructor toJsonCreator.Mode.PROPERTIESto avoid problems:Now it works for
JsonCreator.Mode.DELEGATING:You can play with this example and try out different configurations. Add more constructors, remove some, remove
JsonCreatorannotation from constructor andofmethod and spot the difference.