Its a problem with JAXB. When you create a JAXBContext you must
initialize it with all the classes you are going to marshal. Resteasy
does try a little to help this by adding @SeeAlso classesto the list.
On 10/17/2012 6:48 AM, lu dongping wrote:
> Given two POJO:
>
> @XmlRootElement(name = "Customer")
> @XmlAccessorType(XmlAccessType.FIELD)
> @Produces("application/json")
> public class Customer{
> @XmlElement
> String address = "";
> @GET
> public String get(){
> return "Customer(" + address + ")";
> }
>
> @GET @Path("/address")
> public String getAddress() {
> return address;
> }
>
> public void setAddress(String address) {
> this.address = address;
> }
>
> }
>
> //AND:
>
>
> @XmlRootElement
> @XmlAccessorType(XmlAccessType.FIELD)
> public class Result<T> {
> int count = 0;
> int pageSize = 0;
>
> List<T> records = Collections.emptyList();
>
> public Result(){
> }
>
> public Result(int count, int pageSize, List records){
> this.count = count;
> this.pageSize = pageSize;
> this.records = records;
> }
>
> public int getCount() {
> return count;
> }
>
> public void setCount(int count) {
> this.count = count;
> }
>
> public int getPageSize() {
> return pageSize;
> }
>
> public void setPageSize(int pageSize) {
> this.pageSize = pageSize;
> }
>
> public List<T> getRecords() {
> return records;
> }
>
> public void setRecords(List<T> records) {
> this.records = records;
> }
> }
>
> // And Resource Class:
>
> @Path("/")
> @Produces("application/json")
> public interface HelloWorldService {
> @GET @Path("/customers")
> Result customers();
> }
>
>
> public class HelloWorldServiceImpl implements HelloWorldService {
>
> @Override public Result customers(){
> List lists = new java.util.ArrayList();
> Customer c1 = new Customer();
> Customer c2 = new Customer();
> lists.add(c1);
> lists.add(c2);
> c1.address="123";
> c2.address="456";
> return new Result(2,10,lists);
> }
> }
>
> // main method:
>
>
> public static void main(String[] args) throws Exception {
> ResteasyDeployment deployment = new ResteasyDeployment();
>
> deployment.getResourceClasses().add(HelloWorldServiceImpl.class.getName());
> NettyJaxrsServer netty = new NettyJaxrsServer();
> netty.setDeployment(deployment);
> netty.setPort(9090);
> netty.setRootResourcePath("");
> netty.setSecurityDomain(null);
> netty.start();
> }
>
> When browsing : http://localhost:9090/customers
>
> It will throw Exception:
> [javax.xml.bind.JAXBException: class rest.Customer nor any of its super
> class is known to this context.]
>
> If I change Result<T> to Result<Customer> , then everything is ok.
>
> BTW: I'm using resteasy 2.3.4-Final .
>
> Thanks.
>
> Outersky
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_sfd2d_oct
>
>
>
> _______________________________________________
> Resteasy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/resteasy-users
>
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Resteasy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/resteasy-users