mercredi 15 avril 2015

How to serialize array with jackson json

I am trying to serialize a pojo and its content into JSON using jackson json (fasterxml). However, the Serialization of all types are fine while converting to JSON except the array type of String/INT within a Pojo is ignored.


As a result, my serialized output doesnt contain the Array which i am looking for which contains further details


MyEmployee source



class MyEmployee {
public String name;
public String age;
public java.lang.String[] virtualGroupA;
public java.lang.String[] virtualGroupB;
public String getName() {
return name;
}
public void setName(String name) {
this.name=name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age=age;
}
public java.lang.String[] getVirtualGroupA() {
return virtualGroupA;
}
public void setVirtualGroupA(java.lang.String[] virtualGroupA) {
this.virtualGroupA=virtualGroupA;
}
public java.lang.String[] getVirtualGroupB() {
return virtualGroupB;
}
public void setVirtualGroupB(java.lang.String[] virtualGroupB) {
this.virtualGroupB=virtualGroupB;
}
}


Problem:

While all data is serialized correctly, the array is ignored - Only when run from server as REST call.


JSON output (it creates JSON attribtues for name, age and skips two arrays) - cannot paste the data here as it contains more additional info.


Info:



  • I am using CXF n JAX-RS for my application.

  • I register object mapper for jackson with JAXB Annotations.


For Rest Configurations



Created a Spring context which points to The myMapper is CustomObjectMapper , where i configured the default details such as Annotations etc nothing more.



Additional Info It seems to work fine locally while executing from as standalone program.


Would appreciate any pointers how we can add arrays to be serialized (?) or why it is missing in first place?


Aucun commentaire:

Enregistrer un commentaire