telstra / open-kilda

OpenKilda is an open-source OpenFlow controller initially designed for use in a global network with high control-plane latency and a heavy emphasis on latency-centric data path optimisation.
Apache License 2.0
77 stars 53 forks source link

Add support of Jackson's ParameterNamesModule #880

Open sergii-iakovenko opened 6 years ago

sergii-iakovenko commented 6 years ago

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

nikitamarchenko commented 6 years ago

found http://randomprogram.com/2016/07/07/immutability-lombok-jackson/

abochkarev commented 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.

IlyaMoiseev commented 5 years ago

Made POC repo for avoiding @JsonProperty everywhere until you needed different serialization mapping. It uses builders, and all magic makes in compile time.

abochkarev commented 5 years ago

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.

sergii-iakovenko commented 5 years ago

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

abochkarev commented 5 years ago

@sergii-iakovenko Thanks for your POC. Need time to investigation.

IlyaMoiseev commented 5 years ago

Looks good for me