rest - RestEasy client: How to wrap list elements? -
i trying create resteasy client resteasy rest service, providing entity:
@suppresswarnings("serial") @entity @table(name="product") @xmlrootelement(name="product") public class product implements serializable, ihastraits { @id @generatedvalue(strategy = generationtype.identity) @column(columndefinition = "int unsigned") private long id;
the result is
[{"id":1,"name":"foo","note":null,...}]
then seek read through interface. expect same model class used.
@path("/") public interface restclient { @get @path("/products") @produces("application/json") public list<product> getproducts();
using
registerbuiltin.register(resteasyproviderfactory.getinstance()); this.client = proxyfactory.create(restclient.class, "http://localhost:8080/essc-portal/rest");
but client throws:
caused by: javax.xml.bind.unmarshalexception - linked exception: [com.sun.istack.saxparseexception2; columnnumber: 0; unexpected element (uri:"", local:"id"). expected elements <{}product>]
i've tried add together
@xmlelementwrapper(name="product")
or
@xmlelement(type = product.class, name = "product")
or
@org.jboss.resteasy.annotations.providers.jaxb.wrapped(element = "product")
but neither did help.
how should solve this? i'd prefer not create additional bean class.
what resteasy client expects is:
[{"product":{"id":1,"name":"eap","note":null,"extidjira":null,"extidbugzilla":"226"}]
not
{"products":[{"id":1,"name":"eap","note":null,"extidjira":null,"extidbugzilla":"226"}]}
so ended changed producing method:
public list<productwrapper> getproducts( @context securitycontext sc ) { final list<product> prods = daoprod.getproducts_ordername(0); homecoming rewrap(prods); }
and
private list<productwrapper> rewrap(list<product> prods) { list<productwrapper> p2 = new arraylist(prods.size()); for( product product : prods){ p2.add( new productwrapper(product)); } homecoming p2; }
rest jaxb client resteasy
No comments:
Post a Comment