A message body writer for Java type, class myPackage.B, and MIME media type, application/octet-stream, was not found

后端 未结 10 1347

I am new at RESTful webservices and was trying to update my @OneToMany relationship from a standalone client application, but I am not able to do that. I am usi

相关标签:
10条回答
  • 2020-11-29 07:09

    Include this dependencies in your POM.xml and run Maven -> Update

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.18.1</version>
    </dependency>
    <dependency>
       <groupId>com.owlike</groupId>
       <artifactId>genson</artifactId>
       <version>0.99</version>
    </dependency>
    
    0 讨论(0)
  • 2020-11-29 07:10

    You need to specify the @Provider that @Produces(MediaType.APPLICATION_XML) from B.class
    An add the package of your MessageBodyWriter<B.class> to your /WEB_INF/web.xml as:

    <init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>
    your.providers.package
    </param-value>
    </init-param>
    
    0 讨论(0)
  • 2020-11-29 07:17

    This can also happen if you've recently upgraded Ant. I was using Ant 1.8.4 on a project, and upgraded Ant to 1.9.4, and started to get this error when building a fat jar using Ant.

    The solution for me was to downgrade back to Ant 1.8.4 for the command line and Eclipse using the process detailed here

    0 讨论(0)
  • 2020-11-29 07:20

    Make sure that all these libs are in your class path:

    compile(group: 'com.sun.jersey', name: 'jersey-core',        version: '1.19.4') 
    compile(group: 'com.sun.jersey', name: 'jersey-server',      version: '1.19.4') 
    compile(group: 'com.sun.jersey', name: 'jersey-servlet',     version: '1.19.4')
    compile(group: 'com.sun.jersey', name: 'jersey-json',        version: '1.19.4')
    compile(group: 'com.sun.jersey', name: 'jersey-client',      version: '1.19.4')
    compile(group: 'javax.ws.rs', name: 'jsr311-api', version: '1.1.1')
    compile(group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.2')
    compile(group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.2')
    compile(group: 'org.codehaus.jackson', name: 'jackson-core-asl',   version: '1.9.2')
    compile(group: 'org.codehaus.jackson', name: 'jackson-jaxrs',      version: '1.9.2')
    compile(group: 'org.codehaus.jackson', name: 'jackson-xc',         version: '1.9.2')
    

    Add "Pojo Mapping" and "Jackson Provider" to the jersey client config:

    ClientConfig clientConfig = new DefaultClientConfig();
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    clientConfig.getClasses().add(JacksonJsonProvider.class);
    

    This solve to me!

    ClientResponse response = null;
    
    response = webResource
            .type(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)
            .get(ClientResponse.class);
    
    
    if (response.getStatus() == Response.Status.OK.getStatusCode()) {
    
        MyClass myclass = response.getEntity(MyClass.class);
        System.out.println(myclass);
    }
    
    0 讨论(0)
提交回复
热议问题