掲示板
JSON serialisation
hi,
i need to serialise and deserialise object on JSON. for exemplethis : RoleDefinition
to serialise and deserialize i use this exemple :
the serialization is OK, but when i wan to deserialise the object i have an exception that the class not found.
i tried many alternative but the deserialization still not working correctly.
thanks
i need to serialise and deserialise object on JSON. for exemplethis : RoleDefinition
public class RoleDefinition {
private long companyId;
private ArrayList< String> descriptions;
public ArrayList<string> getDescriptions() {
return descriptions;
}
public void setDescriptions(ArrayList<string> descriptions) {
this.descriptions = descriptions;
}
public long getCompanyId() {
return companyId;
}
public void setCompanyId(long companyId) {
this.companyId = companyId;
}
}</string></string>
to serialise and deserialize i use this exemple :
try {
ServiceContext serviceContext=ServiceContextFactory.getInstance(actionRequest);
RoleDefinition roleDefinition = new RoleDefinition();
roleDefinition.setCompanyId(1990);
ArrayList<string> HM_Langues=new ArrayList<string>();
HM_Langues.add("Italy");
HM_Langues.add("Canada");
HM_Langues.add("DE");
HM_Langues.add("FR");
roleDefinition.setDescriptions(HM_Langues);
//JSONSerializer serializer = JSONFactoryUtil.createJSONSerializer();
//serializer.include("descriptions");
String jsonSerialized=JSONFactoryUtil.Serialize(roleDefinition,"descriptions");
_log.debug("Obj to Json : "+jsonSerialized);
RoleDefinition roleDefinition2= JSONFactoryUtil.Deserialize(jsonSerialized,RoleDefinition.class);
String jsonSerialized2=JSONFactoryUtil.Serialize(roleDefinition2);
_log.debug("Obj2 to Json : "+jsonSerialized2);
} catch (PortalException | SystemException e ) {
// TODO Auto-generated catch block
_log.debug("ERROR : "+e.getMessage());
} </string></string>
the serialization is OK, but when i wan to deserialise the object i have an exception that the class not found.
i tried many alternative but the deserialization still not working correctly.
thanks
8年前 に David H Nebinger によって更新されました。
RE: JSON serialisation
Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
So where's the stack trace?