How do I use the Jersey JSON POJO support?

前端 未结 11 1837
离开以前
离开以前 2020-11-27 12:24

I have an object that I\'d like to serve in JSON as a RESTful resource. I have Jersey\'s JSON POJO support turned on like so (in web.xml):

  
         


        
11条回答
  •  情歌与酒
    2020-11-27 13:13

    You can use @XmlRootElement if you want to use JAXB annotations (see other answers).

    However, if you prefer pure POJO mapping, you must do the following (Unfortunately it isn't written in docs):

    1. Add jackson*.jar to your classpath (As stated by @Vitali Bichov);
    2. In web.xml, if you're using com.sun.jersey.config.property.packages init parameter, add org.codehaus.jackson.jaxrs to the list. This will include JSON providers in the scan list of Jersey.

提交回复
热议问题