Yes, thanks Zack! I looked around for some examples of how @Named is used in the codebase and Nova uses it in many of the domain classes like Flavor [1] and Quota [2].
@ConstructorProperties is a standard JavaBeans annotation which is part of the core JDK classes. My opinion is that we use it with the @Named annotation to facilitate future portability. /jd [1] https://github.com/jclouds/jclouds/blob/master/apis/openstack-nova/src/main /java/org/jclouds/openstack/nova/v2_0/domain/Flavor.java#L135 [2] https://github.com/jclouds/jclouds/blob/master/apis/openstack-nova/src/main /java/org/jclouds/openstack/nova/v2_0/domain/Quota.java#L194 On 5/5/14, 2:06 PM, "Ignasi Barrera" <[email protected]> wrote: >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/jclo >uds/json/config/GsonModule.java#L99-103 >[2] >https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclo >uds/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
