users@jersey.java.net

Re: can't consume json with natural notation

From: Bo Xu <bobxu1128_at_gmail.com>
Date: Fri, 23 Jul 2010 11:58:09 -0700 (PDT)

I tried with a simplistic example. Same error. Maybe a bug?
I will post my code:
For JAXB bean:
@XmlRootElement(name="user")
@XmlAccessorType(XmlAccessType.FIELD)
public class PersonTO {
   private String publicId;

    public String getPublicId() {
        return publicId;
    }

    public void setPublicId(String publicId) {
        this.publicId = publicId;
    }
}
For the resource:
@Path("/echo")
public class Echo {
    @Context
    private UriInfo context;

    public Echo() {
    }

    @GET
    @Produces("text/plain")
    public String get() {
        return "hello world";
    }

    @POST
    @Consumes({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    @Produces("text/plain")
    public String post(PersonTO p )
    {
        return "got it:"+p;
    }
}

For the contextrevoler:

@Provider

public final class JSONJAXBContextResolver implements
ContextResolver<JAXBContext> {

    private final JSONJAXBContext context;
    
    private final Set<Class> types;
    private final Class[] cTypes = {
        PersonTO.class};

    public JSONJAXBContextResolver() throws Exception {
        this.types = new HashSet(Arrays.asList(cTypes));
          this.context = new
JSONJAXBContext(JSONConfiguration.natural().build(), cTypes);
        //this.context = new JSONJAXBContext(cTypes);
        System.out.println("use natural json notation");
    }

    @Override
    public JSONJAXBContext getContext(Class<?> objectType) {
        return (types.contains(objectType)) ? context : null;
    }
}
-- 
View this message in context: http://jersey.576304.n2.nabble.com/can-t-consume-json-with-natural-notation-tp5326726p5330809.html
Sent from the Jersey mailing list archive at Nabble.com.