Re: Cannot get TomEE to use Jackson

2017-08-10 Thread Romain Manni-Bucau
2017-08-10 19:06 GMT+02:00 Thiesius :

> I wasn't pointing out the problem with lazy collections. I had @JsonIgnore
> on
> that property. But since the Jackson didn't kick in, Johnzon skipped the
> annotation and tried to serialize the property.
>
> Anyways the *problem was indeed with the @Provider* annotation. Thank you
> very much for helping me fixing this.
>
> Anyways why is it such a hassle to get it working under TomEE?
>
>
Well it is not linked to tomee by itself. Jackson defines himself as being
a fallback provider so used if no other provider matches the request (based
on JAX-RS 2 rules). Since johnzon is defined to match json as the last one
(so if you drop another json provider it is taken automatically) it has a
higher priority then jackson. If jackson defines himself as matching json
then it would be transparent.



>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/Cannot-get-TomEE-to-use-Jackson-tp4682409p4682416.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>


Re: Cannot get TomEE to use Jackson

2017-08-10 Thread Thiesius
I wasn't pointing out the problem with lazy collections. I had @JsonIgnore on
that property. But since the Jackson didn't kick in, Johnzon skipped the
annotation and tried to serialize the property.

Anyways the *problem was indeed with the @Provider* annotation. Thank you
very much for helping me fixing this.

Anyways why is it such a hassle to get it working under TomEE?



--
View this message in context: 
http://tomee-openejb.979440.n4.nabble.com/Cannot-get-TomEE-to-use-Jackson-tp4682409p4682416.html
Sent from the TomEE Users mailing list archive at Nabble.com.


Re: Cannot get TomEE to use Jackson

2017-08-10 Thread cocorossello
The error is a problem with hibernate and lazy collections. Try returning
just a mocked object, not from database.

Jackson works  in tomee, to get it working you need a @Producer

@Provider
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class JacksonJSONProvider extends
com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider {

public JacksonJSONProvider() {
super();
setMapper(JsonParser.defaultJacksonObjectMapper()); //Your mapper
}

}


See
http://stackoverflow.com/questions/38904640/how-to-use-jackson-as-json-provider-for-jax-rs-client-instead-of-johnzon-in-tome




--
View this message in context: 
http://tomee-openejb.979440.n4.nabble.com/Cannot-get-TomEE-to-use-Jackson-tp4682409p4682411.html
Sent from the TomEE Users mailing list archive at Nabble.com.


Cannot get TomEE to use Jackson

2017-08-10 Thread Thiesius
Hello,

no matter how hard I try I just cannot get TomEE to use Jackson instead of
Johnzon. Want to use Jersey with Jackson

I tried to:
 - Set the providers "cxf.jaxrs.providers" in openejb-jar.xml 
  ( log entry: org.apache.openejb.server.rest.RESTService.deployApplication
Registered JAX-RS Configuration: ...)
 - Extend Jackson provider as

@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class OurJsonProvider
extends com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider {}

I have pom dependencies:

com.fasterxml.jackson.jaxrs
jackson-jaxrs-json-provider
2.9.0
 

 
org.glassfish.jersey.media
jersey-media-json-jackson
2.26-b09
  

etc.

Yet whenever I try to serialize object I get

Caused by: org.hibernate.LazyInitializationException: failed to lazily
initialize a collection of role: ..., could not initialize proxy - no
Session
at
org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:582)
at
org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:201)
at
org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:561)
at
org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:132)
at
org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:277)
at
org.apache.*johnzon*.mapper.MappingGeneratorImpl.writeValue(MappingGeneratorImpl.java:315)

and a lot more johnzon stacktracke lines...

Obviously because I have my properties annotated with Jackson and the object
is serialized with Johnzon instead and it's ignoring my annotations.

What am I doing wrong?

Thank you



--
View this message in context: 
http://tomee-openejb.979440.n4.nabble.com/Cannot-get-TomEE-to-use-Jackson-tp4682409.html
Sent from the TomEE Users mailing list archive at Nabble.com.