java - Jersey serialize empty list and single element list as an array -
since there probelm serialization emplty list , single element list in jersey. tried fix adding jaxbcontextresolver class. goal return json object thant contains json array android application in cases (if returns 0 element or 1 element or more 1). json data don't same. , error in android application expected begin_object begin_array
appreciate help. in advance
@provider public class jaxbcontextresolver implements contextresolver<jaxbcontext> { private jaxbcontext context; private final set<class> types; // pojo class private class[] ctypes = { workitem.class, project.class, user.class }; public jaxbcontextresolver() throws exception { naturalbuilder builder = jsonconfiguration.natural(); //assure rootelement name appears in json structure builder.rootunwrapping(false); this.types = new hashset(arrays.aslist(ctypes)); // json configuration this.context = new jsonjaxbcontext(builder.build(), ctypes); } @override public jaxbcontext getcontext(class<?> objecttype) { return (types.contains(objecttype)) ? context : null; } }
my json data when set builder.rootunwrapping(true);
[ { "assignedto": "assignee1", "businesskey": "key1", "createdby": "createdby1", "description": "description1" } ]
but want solve problem in android side :
{ "project": [ { "assignedto": "assignee1", "businesskey": "key1", "createdby": "createdby1", "description": "description1" } ] }
i added @jsonrootname(value = "project")
my project class in order fix problem error don't khow how solve please need
multiple markers @ line - jsonrootname cannot resolved type - attribute value undefined annotation type jsonrootname
my project class :
@xmlrootelement @jsonrootname(value = "project") public class project implements serializable { private static final long serialversionuid = 1l; private string description; private string businesskey; private string createdby; private string assignedto; public project() { } // getter , setter method }
try change annotation of project class as
@jsonrootname(value = "rootname")
Comments
Post a Comment