Open sergii-iakovenko opened 6 years ago
@sergii-iakovenko We've already tried this way - unfortunately, not everything as well as wanted. If you have a couple constructors in a class it won't work. Also we need to pass a special parameter to java compiler (compile with -parameters argument) to mark constructor's signature with names of variables. I would suggest using @JsonProperty in constructors as it was before, but we can avoid annotating with @JsonProperty fields in classes. Using @JsonNaming and strategies fully resolves it.
Made POC repo for avoiding @JsonProperty
everywhere until you needed different serialization mapping.
It uses builders, and all magic makes in compile time.
I've looked at the code in the POC repo - looks very interesting. It really helps us don't use @JsonProperty explicitly. I asked @IlyaMoiseev to extend this project to cover cases with: ignoring unneeded fields, adding extra constructors and fabric methods, switching from Java 7 to Java 8, etc. @nikitamarchenko @sergii-iakovenko @surabujin Let's discuss - the promising solution.
There's no need to use builders so heavily if either ParameterNamesModule or ParanamerModule is used. Please, check the modified PoC - https://github.com/sergii-iakovenko/lombokjackson
@sergii-iakovenko Thanks for your POC. Need time to investigation.
Looks good for me
In order to minimize boilerplate code for Json serialization we can enable Jackson's Java8 ParameterNamesModule. As a result, constructors and builder methods of serializable entities can be used without annotating each argument with @JsonProperty.
See https://github.com/FasterXML/jackson-modules-java8/tree/master/parameter-names