xml - List<JAXBElement> in adapter code impacting JSON format -


i format json output contain string objects having 1 element , not array. below pojo.

  @component("myvo") @scope("prototype") @xmlrootelement @xmlaccessortype(xmlaccesstype.none) @xmltype(proporder = {"a", "b", "c", "d", "e", "f", "sectionlist"}) public class myvo extends serviceresponseto {  private static final long serialversionuid = -9190950749517871535l;  @xmlelement(name="abc") private string a;  @xmlelement(name="def") private string b;  @xmlelement(name="ghi") private string c;  @xmlelement(name="jkl") private string d;  @xmlelement(name="mno") private string e;  @xmlelement(name="pqr") private string f;  @xmlelement(name="section") @xmljavatypeadapter(myadapter.class) private list<map<string, string>> sectionlist ;      //corresponding getters , setters  @override public string tostring() {     return "detailsvo [a=" + + ", b=" + b             + ", c=" + c + ", d=" + d             + ", e=" + e + ", f=" + f             + ", sectionlist=" + sectionlist+ "]"; }   } 

the issue adapter code below.

    class myadapter extends xmladapter<keyvaluesasnodelist, map<string, string>> {       public keyvaluesasnodelist marshal(map<string,string> map) throws exception {         keyvaluesasnodelist maptype = new keyvaluesasnodelist();             for(map.entry<string,string> entry : map.entryset()){                 if(entry.getkey().equalsignorecase("key1")                     maptype.key1 = entry.getvalue().tostring();                  if(entry.getkey().equalsignorecase("key2")                     maptype.key2 = entry.getvalue().tostring();                  if(entry.getkey().equalsignorecase("key3")                     maptype.key3 = entry.getvalue().tostring();                  if(entry.getkey().equalsignorecase("key3")                     maptype.key3 = entry.getvalue().tostring();                  if( entry.getvalue().getclass().equals(hashmap.class) || entry.getvalue().getclass().equals(linkedhashmap.class)){                     maptype.entries.add(new jaxbelement(new qname(entry.getkey(),string,class,marshal(entry.getvalue()))));                 }                 else{                        // issue mentioned.. value string.. enters part. here problem lies                     maptype.entries.add(new jaxbelement(new qname(entry.getkey(),string,class,entry.getvalue())));                 }              }            } }         public map<string, string> unmarshal(map<string, string> ) throws exception {            return null;       } }    class keyvaluesasnodelist {   @xmlattribute    public string key1 ;    @xmlattribute   public integer key2;     @xmlattribute    public string  key3;     @xmlattribute    public string key4;     //since have given jaxbelement list, strings retured array in json.      list<jaxbelement> entries = new arraylist<jaxbelement>(); } 

using above adapter, if try convert json, response formed below.

{"returncode":"00","response":{"type":"myvo","abc":"a","def":"b","ghi":"c","jkl":"d","mno":"e","pqr":"f","section":[{"name":"sectionone","configuration":"ooo","name":["n"],"sectionname":["a"]}]}} 

the above response contains json array single element. want above output formed below.

the response need is:

{"returncode":"00","response":{"type":"myvo","abc":"a","def":"b","ghi":"c","jkl":"d","mno":"e","pqr":"f","section":[{"name":"sectionone","configuration":"ooo","name":"n","sectionname":"a"}]}} 

i dont want array name , sectionname. change adapter in such way desired json output , doesnot affect xml

p.s: this, adapter, xml response perfect. appreciated. thanks.

change data type of sectionlist field to:

private map<string, string> sectionlist ; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -