java - Gson Custom Serializer Not Called -


i have class doesn't serialize gson (class name , hashmap) wrote custom serializer print name , key, value pair hashmap.

public jsonelement serialize(specificationgrouplist sgl, type typeoft,     jsonserializationcontext context) { system.out.println("here"); jsonobject ret = new jsonobject(); ret.addproperty("groupname", sgl.getgroupname());  jsonarray jsonarray = new jsonarray(); ret.add("specificationpartlist", jsonarray); (entry<string, string> entry : sgl.getspecificationpairlist().entryset()) {     jsonobject temp = new jsonobject();     temp.addproperty(entry.getkey(), entry.getvalue());     jsonarray.add(temp); }  return ret; } 

to print appropriately, i've registered custom serializer when go print class, doesn't use serializer. can tell because have serializer printing "here" , never prints.

private void printproducts() { gson gson = new gsonbuilder().setprettyprinting()     .registertypeadapter(specificationgrouplist.class, new specgrouplistserializer())     .create(); system.out.println(gson.getadapter(specificationgrouplist.class).tostring()); (item : items) {     system.out.println(gson.tojson(i));     system.out.println("sgl" + gson.tojson(i.getspecificationgrouplist())); } } 

also, prints , serializing entire object doesn't work expect nor trying print object directly.

{   "itemnumber": "22-148-842",   "neweggitemnumber": "n82e16822148842",   "title": "seagate savvio 15k.3 st9300653ss 300gb 15000 rpm 2.5\" sas 6gb/s internal enterprise hard drive -bare drive",   "specificationgrouplist": [] } sgl[] 

any appreciated.

of course, can't directly copy code in i've gotten rid of , wasn't yet point i'd start versioning essentially:

arraylist<item> items = new arraylist<item>(); gson gson = new gson  (item : items){     i.setid(something); }  (item : items){     //...     //send query , response here     //...      = gson.fromjson(in, item.class);  } 

setting i returned item didn't work , when tried serialize, hashmap in objects wasn't set @perception noted. "solved" creating list of strings hold something , added returned items arraylist instead of trying assign existing item.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -