johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: @JsonbPropertyOrder behaviour
Date Wed, 10 May 2017 11:26:43 GMT
In the spec you will find (4.2):

To customize the order of serialized properties only for one specific type,
> JSON Binding provides javax.json.bind.annotation.JsonbPropertyOrder
> annotation. Order specified by JsonbPropertyOrder annotation overrides
> order specified by PropertyOrderStrategy. The order is applied to already
> renamed properties as stated in 4.1.


So for me Johnzon looks right in that regard.

I think the missing property case is unspecified - didnt find it at least -
but like the fact we respect the order of the specified ones and add other
ones. If it is intended to be ignored there is the ignore annotation so
sounds good for me.

Do you read it differently?



Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2017-05-10 12:40 GMT+02:00 Ravisankar Challa <ravisankar2@gmail.com>:

> Hi there,
>
> I am evaluation jsob implementations yasson and  apache johnzon.
>
> I found some differences in the way the @JsonbPropertyOrder annotation is
> treated by the two implementations.
>
> This is my pojo.
>
> @JsonbPropertyOrder(value = {"personGender","personName", "personAge"})
> public class Person {
>
>     private String personName;
>     private int personAge;
>     private String personGender;
>
>     public String getPersonName() {
>         return personName;
>     }
>     public void setPersonName(String name) {
>         this.personName = name;
>     }
>     public int getPersonAge() {
>         return personAge;
>     }
>     public void setPersonAge(int age) {
>         this.personAge = age;
>     }
>     public String getPersonGender() {
>         return personGender;
>     }
>     public void setPersonGender(String personGender) {
>         this.personGender = personGender;
>     }
> }
>
> JsonbConfig config = new
> JsonbConfig().withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_
> CASE_WITH_UNDERSCORES);
>         Jsonb jsonb = JsonbBuilder.create(config);
>         Person p = new Person();
>         p.setPersonAge(12);
>         p.setPersonName("David");
>         p.setPersonGender("Male");
>         System.out.println(jsonb.toJson(p));
>
> 1) @JsonbPropertyOrder(value = {"personGender","personName", "personAge"})
>   Yasson: {"person_gender":"Male","person_name":"David","person_age":12}
>   Johnzon: {"person_name":"David","person_age":12,"person_gender":"Male"}
> --
> *incorrect*
>
> 2) @JsonbPropertyOrder(value = {"person_gender","person_name",
> "person_age"})
>    Yasson: {} - *empty json object*
>   Johnzon: {"person_gender":"Male","person_name":"David","person_age":12}
> -- *correct*
>
> 3)@JsonbPropertyOrder(value = {"personGender", "personAge"})
>   Yasson: {"person_gender":"Male","person_age":12} -- *If a field name is
> not specified in property order it is ignored*
>   @JsonbPropertyOrder(value = {"person_gender", "person_age"})
>   {"person_name":"David","person_gender":"Male","person_age":12} --* all
> the fields are serialized;*
>
> Yasson pom.xml
> <dependencies>
>    <dependency>
>         <groupId>javax.json.bind</groupId>
>         <artifactId>javax.json.bind-api</artifactId>
>         <version>1.0.0-M2</version>
>     </dependency>
>     <dependency>
>         <groupId>org.eclipse</groupId>
>         <artifactId>yasson</artifactId>
>         <version>1.0.0-M2</version>
>     </dependency>
>     <dependency>
>         <groupId>org.glassfish</groupId>
>         <artifactId>javax.json</artifactId>
>         <version>1.1.0-M2</version>
>     </dependency>
>   </dependencies>
>
>   <repositories>
>     <!-- Needed for Yasson -->
>     <repository>
>         <id>yasson-releases</id>
>         <name>Yasson Snapshots repository</name>
>         <url>https://repo.eclipse.org/content/repositories/yasson-releases
> </url>
>     </repository>
> </repositories>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message