Discussion:
Using Jackson as JSON body reader/writer with DOSGi
Julio Carlos Barrera Juez
2013-06-14 07:58:17 UTC
Permalink
I want to serialize my REST Requests and Responses in JSON. I want to use
FasterXML Jackson [1] to perform this task. I'm using DOSGi 2.7.4 and
Jackson 2.2.3-SNAPSHOT. My model objects are JAXB annotated and my REST WS
is declared like this:

...
@Path("/foo")
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public ModelObjectB foo(ModelObjectA ModelObjectA);
...

I register it as an OSGi service using DOSGi
property "org.apache.cxf.rs.provider" with value
"com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider".

But when I call the WS, I get:

"No message body reader has been found for request class ModelObjectA,
ContentType : application/json."

What am I missing?

Moreover, it is possible to configure JacksonJaxbJsonProvider, or do I need
to extend the class with a custom configured class?

Thank you!

[1] FasterXML Jackson - http://wiki.fasterxml.com/JacksonHome
Sergey Beryozkin
2013-06-14 08:46:36 UTC
Permalink
Hi
Post by Julio Carlos Barrera Juez
I want to serialize my REST Requests and Responses in JSON. I want to use
FasterXML Jackson [1] to perform this task. I'm using DOSGi 2.7.4 and
Jackson 2.2.3-SNAPSHOT. My model objects are JAXB annotated and my REST WS
...
@Path("/foo")
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public ModelObjectB foo(ModelObjectA ModelObjectA);
...
I register it as an OSGi service using DOSGi
property "org.apache.cxf.rs.provider" with value
"com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider".
"No message body reader has been found for request class ModelObjectA,
ContentType : application/json."
What am I missing?
I think it is that Jackson 2.2.x related issue that I believe has been
fixed. Try CXF 2.7.6-SNAPSHOT please.
Post by Julio Carlos Barrera Juez
Moreover, it is possible to configure JacksonJaxbJsonProvider, or do I need
to extend the class with a custom configured class?
Have a look at the example at the of this post:
http://cxf.547215.n5.nabble.com/JaxRs-Yet-another-Unmarshall-Marshall-issue-with-CXF-2-7-2-tt5729213.html#a5729235

Sergey
Post by Julio Carlos Barrera Juez
Thank you!
[1] FasterXML Jackson - http://wiki.fasterxml.com/JacksonHome
--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com
NCorbet
2013-06-14 13:17:10 UTC
Permalink
Julio,

Here is configuration I added to my spring file to use
JacksonJaxbJsonProvider:

<bean id="jaxbAnnotationInspector"
class="org.codehaus.jackson.xc.JaxbAnnotationIntrospector" />
<bean id="jacksonObjectMapper"
class="org.codehaus.jackson.map.ObjectMapper">
<property name="annotationIntrospector" ref="jaxbAnnotationInspector" />
</bean>

<bean id="jsonProvider"
class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />

You need to set the jaxbAnnotationIntrospector in the ObjectMapper so it
forces Jackson to look at JaxB annotations first. This worked well for
me...until I needed to Marshall/UnMarshall abstract types. If you are ok
with mixing Jackson and Jaxb annotations then this should be no big deal to
you ( the abstract type issue that is, the rest worked fine).

Hope that helps



--
View this message in context: http://cxf.547215.n5.nabble.com/Using-Jackson-as-JSON-body-reader-writer-with-DOSGi-tp5729257p5729278.html
Sent from the cxf-user mailing list archive at Nabble.com.
Julio Carlos Barrera Juez
2013-06-14 13:19:58 UTC
Permalink
Thank you very much, I will try it on Monday ;-) Have a nice weekend!
Post by NCorbet
Julio,
Here is configuration I added to my spring file to use
<bean id="jaxbAnnotationInspector"
class="org.codehaus.jackson.xc.JaxbAnnotationIntrospector" />
<bean id="jacksonObjectMapper"
class="org.codehaus.jackson.map.ObjectMapper">
<property name="annotationIntrospector"
ref="jaxbAnnotationInspector" />
</bean>
<bean id="jsonProvider"
class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
You need to set the jaxbAnnotationIntrospector in the ObjectMapper so it
forces Jackson to look at JaxB annotations first. This worked well for
me...until I needed to Marshall/UnMarshall abstract types. If you are ok
with mixing Jackson and Jaxb annotations then this should be no big deal to
you ( the abstract type issue that is, the rest worked fine).
Hope that helps
--
http://cxf.547215.n5.nabble.com/Using-Jackson-as-JSON-body-reader-writer-with-DOSGi-tp5729257p5729278.html
Sent from the cxf-user mailing list archive at Nabble.com.
Julio Carlos Barrera Juez
2013-06-17 10:19:59 UTC
Permalink
Hi!

I'm trying to achieve the same configuration than you, Neil. I'm not using
Spring, but Blueprint. Moreover, I have a multi-bundle configuration. I
have DOSGi that offers REST API of my services published in the OSGi
Service Registry. I have one of these services that needs to be serialized
using JSON instead of XML. Then, I want to use Jackson 2.2.x (FasterXML
Maven group ID, not Codehaus) as JSON provider, but I don't know how to
tell DOSGi using my own JSON provider.

I have tried using DOSGi property "org.apache.cxf.rs.provider" with value
"com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider", but I get:

"No message body reader has been found for request class ModelObjectA,
ContentType : application/json."

and "415 Unsupported Media Type" in client.

I have tried to declare my JSON provider as a bean in my blueprint, but I
does not work. The problem is that "DOSGi is not declared in any place", it
is an OSGi feature declared as a bundle in my OSGi container. Then, I have
no way to configure it.

What can I do?

Thank you very much.


On 14 June 2013 15:19, Julio Carlos Barrera Juez <
Post by Julio Carlos Barrera Juez
Thank you very much, I will try it on Monday ;-) Have a nice weekend!
Post by NCorbet
Julio,
Here is configuration I added to my spring file to use
<bean id="jaxbAnnotationInspector"
class="org.codehaus.jackson.xc.JaxbAnnotationIntrospector" />
<bean id="jacksonObjectMapper"
class="org.codehaus.jackson.map.ObjectMapper">
<property name="annotationIntrospector"
ref="jaxbAnnotationInspector" />
</bean>
<bean id="jsonProvider"
class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
You need to set the jaxbAnnotationIntrospector in the ObjectMapper so it
forces Jackson to look at JaxB annotations first. This worked well for
me...until I needed to Marshall/UnMarshall abstract types. If you are ok
with mixing Jackson and Jaxb annotations then this should be no big deal to
you ( the abstract type issue that is, the rest worked fine).
Hope that helps
--
http://cxf.547215.n5.nabble.com/Using-Jackson-as-JSON-body-reader-writer-with-DOSGi-tp5729257p5729278.html
Sent from the cxf-user mailing list archive at Nabble.com.
Sergey Beryozkin
2013-06-17 10:34:13 UTC
Permalink
Hi
Post by Julio Carlos Barrera Juez
Hi!
I'm trying to achieve the same configuration than you, Neil. I'm not using
Spring, but Blueprint. Moreover, I have a multi-bundle configuration. I
have DOSGi that offers REST API of my services published in the OSGi
Service Registry. I have one of these services that needs to be serialized
using JSON instead of XML. Then, I want to use Jackson 2.2.x (FasterXML
Maven group ID, not Codehaus) as JSON provider, but I don't know how to
tell DOSGi using my own JSON provider.
I have tried using DOSGi property "org.apache.cxf.rs.provider" with value
"No message body reader has been found for request class ModelObjectA,
ContentType : application/json."
and "415 Unsupported Media Type" in client.
It may be related to the fact CXF 2.7.2 does not correctly recognize
Jackson 2.2.x - try CXF 2.7.6-SNAPSHOT - or use earlier Jackson version
for now

Cheers, Sergey
Post by Julio Carlos Barrera Juez
I have tried to declare my JSON provider as a bean in my blueprint, but I
does not work. The problem is that "DOSGi is not declared in any place", it
is an OSGi feature declared as a bundle in my OSGi container. Then, I have
no way to configure it.
What can I do?
Thank you very much.
On 14 June 2013 15:19, Julio Carlos Barrera Juez <
Post by Julio Carlos Barrera Juez
Thank you very much, I will try it on Monday ;-) Have a nice weekend!
Post by NCorbet
Julio,
Here is configuration I added to my spring file to use
<bean id="jaxbAnnotationInspector"
class="org.codehaus.jackson.xc.JaxbAnnotationIntrospector" />
<bean id="jacksonObjectMapper"
class="org.codehaus.jackson.map.ObjectMapper">
<property name="annotationIntrospector"
ref="jaxbAnnotationInspector" />
</bean>
<bean id="jsonProvider"
class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
You need to set the jaxbAnnotationIntrospector in the ObjectMapper so it
forces Jackson to look at JaxB annotations first. This worked well for
me...until I needed to Marshall/UnMarshall abstract types. If you are ok
with mixing Jackson and Jaxb annotations then this should be no big deal to
you ( the abstract type issue that is, the rest worked fine).
Hope that helps
--
http://cxf.547215.n5.nabble.com/Using-Jackson-as-JSON-body-reader-writer-with-DOSGi-tp5729257p5729278.html
Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com
Julio Carlos Barrera Juez
2013-06-18 12:45:57 UTC
Permalink
Hi!

I have achieved my objective using Jackson old 1.9.12 version, the last
version I've found in old Codehaus Maven old naming artifacts [1].

Thank you both, Sergey and Neil!

Regards, Julio.

[1] Maven Codehaus Jackson in Maven Repo1
http://repo1.maven.org/maven2/org/codehaus/jackson/
Hi
Post by Julio Carlos Barrera Juez
Hi!
I'm trying to achieve the same configuration than you, Neil. I'm not using
Spring, but Blueprint. Moreover, I have a multi-bundle configuration. I
have DOSGi that offers REST API of my services published in the OSGi
Service Registry. I have one of these services that needs to be serialized
using JSON instead of XML. Then, I want to use Jackson 2.2.x (FasterXML
Maven group ID, not Codehaus) as JSON provider, but I don't know how to
tell DOSGi using my own JSON provider.
I have tried using DOSGi property "org.apache.cxf.rs.provider" with value
"No message body reader has been found for request class ModelObjectA,
ContentType : application/json."
and "415 Unsupported Media Type" in client.
It may be related to the fact CXF 2.7.2 does not correctly recognize
Jackson 2.2.x - try CXF 2.7.6-SNAPSHOT - or use earlier Jackson version for
now
Cheers, Sergey
I have tried to declare my JSON provider as a bean in my blueprint, but I
Post by Julio Carlos Barrera Juez
does not work. The problem is that "DOSGi is not declared in any place", it
is an OSGi feature declared as a bundle in my OSGi container. Then, I have
no way to configure it.
What can I do?
Thank you very much.
On 14 June 2013 15:19, Julio Carlos Barrera Juez <
Thank you very much, I will try it on Monday ;-) Have a nice weekend!
Post by NCorbet
Julio,
Post by NCorbet
Here is configuration I added to my spring file to use
<bean id="jaxbAnnotationInspector"
class="org.codehaus.jackson.**xc.JaxbAnnotationIntrospector" />
<bean id="jacksonObjectMapper"
class="org.codehaus.jackson.**map.ObjectMapper">
<property name="annotationIntrospector"
ref="jaxbAnnotationInspector" />
</bean>
<bean id="jsonProvider"
class="org.codehaus.jackson.**jaxrs.JacksonJaxbJsonProvider" />
You need to set the jaxbAnnotationIntrospector in the ObjectMapper so it
forces Jackson to look at JaxB annotations first. This worked well for
me...until I needed to Marshall/UnMarshall abstract types. If you are ok
with mixing Jackson and Jaxb annotations then this should be no big deal to
you ( the abstract type issue that is, the rest worked fine).
Hope that helps
--
http://cxf.547215.n5.nabble.**com/Using-Jackson-as-JSON-**
body-reader-writer-with-DOSGi-**tp5729257p5729278.html<http://cxf.547215.n5.nabble.com/Using-Jackson-as-JSON-body-reader-writer-with-DOSGi-tp5729257p5729278.html>
Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
NCorbet
2013-06-18 13:18:59 UTC
Permalink
No problem. Glad we could help. I should have posted that I used Jackson 1.8.
Sorry.



--
View this message in context: http://cxf.547215.n5.nabble.com/Using-Jackson-as-JSON-body-reader-writer-with-DOSGi-tp5729257p5729448.html
Sent from the cxf-user mailing list archive at Nabble.com.

Loading...