java - Json to xml conversion generating confusing xml string -


i have dto class converting json , storing db. need corresponding xml file json.

class foodto {     private string id;     // array of strings.     private arraylist<string> names;     // object of other class having 2 values string socid , string socname.     private someotherclass soc; } 

i using gson google library create json object , xml string.

foodto foodto = new foodto(); gson gson = new gson(); string jsonstring = gson.tostring(foodto); jsonobject json = new jsonobject(jsonstring); string xmlstring = xml.tostring(json, "parent"); 

when each member of foodto object contains value generates perfect xml.

<parent>   <id>some id</id>   <names>john</names>   <names>mac</names>   <soc>     <socid>123</socid>     <socname>xyz</socname>   </soc> </parent> 

but problem when value in object empty generates confusing xml not possible convert same json , class object afterwards.

for empty object json string is

{id:"", names:[""], soc:{}}

for json xml string is

<parent>   </id>   </names>   <soc></soc> </parent> 

regenerating json xml

{id:{}, names:{}, soc:{}}

and causing error when creating class object json expecting id string , names array of string. there other better way this?


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -