hstaudacher / osgi-jax-rs-connector

An OSGi - JAX-RS 2.0 Connector, software repository available on the link below
http://hstaudacher.github.io/osgi-jax-rs-connector
Other
191 stars 98 forks source link

json serialization not working #25

Closed sschober closed 10 years ago

sschober commented 10 years ago

I try to marshall an entity (annotated with @XmlRootElement) and no MessageBodyWrite is found:

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class de.uulm.ic2.entities.IC2Node, genericType=class de.uulm.ic2.entities.IC2Node.

My service is definied like this:

    @GET
    @Path("node")
    @Produces(MediaType.APPLICATION_JSON)
    public IC2Node getNode(){
        return new IC2Node(0, HOSTNAME_KEY, IP_KEY, 0, ASN_KEY, new ASN());
    }

I am including/starting the gson provider bundle

osgi> ss | grep eclipsesource
68  ACTIVE      com.eclipsesource.jaxrs.publisher_3.1.0.201309301542
70  ACTIVE      com.eclipsesource.jaxrs.provider.gson_1.0.0.201309301542

Am I missing something here?

sschober commented 10 years ago

XML serialization is working just fine, btw...

sschober commented 10 years ago

Please let my know if you need further information.

hstaudacher commented 10 years ago

Hi @sschober, I don't think I need further information. I just need the time to fix it ;). Hopefully next week will be a free slot were I can do the work.

BryanHunt commented 10 years ago

As a workaround, you could try using the Moxy provider

dcaillia commented 10 years ago

Maybe this relates to issue #30 (ordering of bundles).

hstaudacher commented 10 years ago

Hmm, I have investigated deeper here. This was the exampel I have used:

@Path( "/osgi-jax-rs" )
public class ExampleService {

  public static class Foo {

    private final String a;
    private final String b;

    public Foo( String a, String b ) {
      this.a = a;
      this.b = b;
    }

    public String getA() {
      return a;
    }

    public String getB() {
      return b;
    }

  }

  @GET
  @Produces( MediaType.APPLICATION_JSON )
  public Map<String, Foo> seyHello() {
    HashMap<String, Foo> map = new HashMap<String, Foo>();
    map.put( "foo", new Foo( "first", "second" ) );
    map.put( "bar", new Foo( "third", "fourth" ) );
    return map;
  }
}

and it's producing:

{"foo":{"a":"first","b":"second"},"bar":{"a":"third","b":"fourth"}}

this is my ss:

0   ACTIVE      org.eclipse.osgi_3.8.0.v20120529-1548
1   ACTIVE      org.eclipse.jetty.io_8.1.3.v20120522
2   ACTIVE      org.eclipse.jetty.http_8.1.3.v20120522
3   ACTIVE      org.eclipse.equinox.http.jetty_3.0.0.v20120522-1841
4   ACTIVE      org.eclipse.jetty.server_8.1.3.v20120522
5   ACTIVE      org.glassfish.hk2.external.cglib_2.2.0.b18
6   ACTIVE      org.glassfish.jersey.core.jersey-client_2.3.1
7   ACTIVE      org.eclipse.jetty.util_8.1.3.v20120522
8   ACTIVE      org.eclipse.jetty.continuation_8.1.3.v20120522
9   ACTIVE      org.glassfish.hk2.utils_2.2.0.b18
10  ACTIVE      org.eclipse.jetty.servlet_8.1.3.v20120522
11  ACTIVE      javax.validation.api_1.1.0.Final
12  ACTIVE      org.glassfish.jersey.core.jersey-server_2.3.1
13  ACTIVE      com.eclipsesource.jaxrs.provider.gson_1.0.0.qualifier
14  ACTIVE      org.apache.felix.gogo.shell_0.8.0.v201110170705
15  ACTIVE      org.eclipse.equinox.console_1.0.0.v20120522-1841
16  ACTIVE      javax.ws.rs-api_2.0.0
17  ACTIVE      org.glassfish.hk2.external.javax.inject_2.2.0.b18
18  ACTIVE      org.glassfish.hk2.api_2.2.0.b18
19  ACTIVE      org.glassfish.hk2.locator_2.2.0.b18
20  ACTIVE      org.eclipse.jetty.security_8.1.3.v20120522
21  ACTIVE      com.eclipsesource.jaxrs.publisher_3.1.0.qualifier
22  ACTIVE      com.google.gson_2.2.2
23  ACTIVE      javax.annotation-api_1.2.0.b04
24  ACTIVE      org.glassfish.hk2.external.asm-all-repackaged_2.2.0.b18
25  ACTIVE      org.glassfish.hk2.osgi-resource-locator_1.0.1
26  ACTIVE      org.glassfish.jersey.core.jersey-common_2.3.1
27  ACTIVE      org.eclipse.osgi.services_3.3.100.v20120522-1822
28  ACTIVE      org.eclipse.equinox.http.servlet_1.1.300.v20120522-1841
29  ACTIVE      org.glassfish.jersey.containers.jersey-container-servlet-core_2.3.1
30  ACTIVE      org.apache.felix.gogo.command_0.8.0.v201108120515
31  ACTIVE      com.google.guava_14.0.1
32  ACTIVE      javax.servlet-api_3.0.1
33  ACTIVE      com.eclipsesource.jaxrs.connector.example_1.0.0.qualifier
34  ACTIVE      org.eclipse.equinox.cm_1.0.400.v20120522-1841
35  ACTIVE      org.apache.felix.gogo.runtime_0.8.0.v201108120515

So, from my point of view everything works as expected.

I will close the issue. Please reopen it if the problem still exist with further information.