Can I marshal List<? extends BaseObject> to json with Moxy (Jersey 2.17) out of box? -
jersey 2.17 moxy.
model:
@xmltype(name="product.product") @xmlaccessortype(xmlaccesstype.field) public abstract class product { } @xmltype(name="product.paperproduct") @xmlaccessortype(xmlaccesstype.field) public class paperproduct extends product { } @xmltype(name="product.woodproduct") @xmlaccessortype(xmlaccesstype.field) public class woodproduct extends product { }
resource find paperproduct:
@get @path("paperproduct") public response findpaperproducts() { list<paperproduct> products = findservice.findpaperproducts(); genericentity genericentity = new genericentity(products, new parameterizedtypeimpl(list.class, paperproduct.class)); return response.ok(genericentity, responsemediatype).build(); }
json result (good):
[ { "@xsi:type" : "product.paperproduct", "name" : "note book", }]
resource find products, including woodproduct:
@get @path("product") public response findallproducts() { list<product> products = findservice.findproducts(); genericentity genericentity = new genericentity(products, new parameterizedtypeimpl(list.class, product.class)); return response.ok(genericentity, responsemediatype).build(); }
json result (not want):
[ { "@xsi:type" : "product.product", "name" : "note book" }, { "@xsi:type" : "product.product", "name" : "chair"}]
the result want is:
[ { "@xsi:type" : "product.paperproduct", "name" : "note book" }, { "@xsi:type" : "product.woodproduct", "name" : "chair"}]
how can result want?
Comments
Post a Comment