How to produce JSON output with Jersey 1.6 using JAXB

后端 未结 6 856
忘了有多久
忘了有多久 2020-11-30 07:41
@XmlRootElement
public class Todo {
    private String s = \"test\";

    public String getS() {
        return s;
    }

    public void setS(String s) {
        th         


        
6条回答
  •  借酒劲吻你
    2020-11-30 08:11

    The other answers didn't work for me, but I finally got it to work with JSON.

    I was using the jersey-bundle-1.17.jar (also tried with the asm-3.1.jar and jersey-json-1.17.jar added to classpath and still didn't work). I finally tried downloading the zip that includes 12 different jars. Once I added all 12 jars to my classpath I finally got rid of the error and works great returning JSON.

    I hope this helps somebody.

    Update: Here is a link to the zip file that contains the 12 jar files: jersey-archive-1.17.zip

    Another Update for Maven Users: Add the following to your pom.xml to get the 12 jars individually:

        
            com.sun.jersey
            jersey-servlet
            1.17.1
        
        
            com.sun.jersey
            jersey-client
            1.17.1
        
        
            com.sun.jersey
            jersey-json
            1.17.1
        
        
            com.sun.jersey
            jersey-core
            1.17.1
        
        
            com.sun.jersey
            jersey-server
            1.17.1
        
        
            org.codehaus.jackson
            jackson-core-asl
            1.9.2
        
        
            org.codehaus.jackson
            jackson-mapper-asl
            1.9.2
        
        
            org.codehaus.jackson
            jackson-jaxrs
            1.9.2
        
        
            org.codehaus.jackson
            jackson-xc
            1.9.2
        
        
            org.codehaus.jettison
            jettison
            1.1
        
        
            javax.ws.rs
            jsr311-api
            1.1.1
        
        
            asm
            asm
            3.1
        
    

提交回复
热议问题