Thanks for bringing this up Zack! The SerializedName and Named annotatioms are used only to serialize objects [1] and are the only ones that can be used to configure the property names. I also prefer the SerializedName one.
The ConstructorProperties one [2] is used only when deserializing. Another thing to take care of (I always try to do it) is to require, in the PRs, to specify the corresponding SerializedName annotations for each field that has a different serialized form, even if the domain object is not going to be serialized. That will make the whole model consistent and easier to evolve the apis. I. [1] https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/json/config/GsonModule.java#L99-103 [2] https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/json/config/GsonModule.java#L123-127 El 05/05/2014 22:40, "Zack Shoylev" <[email protected]> escribió: > When deserializing/serializing an object, the jclouds GSON supports > multiple annotations for defining variable names. > Example: you have some_value in JSON but in a jclouds domain class it > should be someValue. > We have (at least): > > @SerializedName (a GSON-specific annotation, applied to member variable) > @Named (guice injection annotation, applied to member variable) > @ConstructorProperties (java beans annotation, and applied to the > constructor of the domain object) > > I am not actually sure if @ConstructorProperties works for serialization > (it works when deserializing). > > I have seen all these 3 used. My personal preference is to only use > @SerializedName, and only where needed. Can I get some more > opinions/insight/feedback on these annotations? > > Thanks! > Zack
