Discussion:
Johnzon is going to infinite loop on JPA entities with OneToMany relationship
sudhakarvm
2018-07-19 14:45:56 UTC
Permalink
I am facing problem while json is generated from my JPA model object using
default JSON provider Johnzon.
This JPA entity class B has @ManyToOne relationship with other entity A.
Since A also includes B as @OneToMany member with List datatype. Because of
this Johnzon is going in infinite loop to prepare the json and I am getting
following exception:

/Caused by: javax.json.stream.JsonGenerationException: Invalid json
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:437)/

JPA (using eclipselink) is returning correct results. Any suggestions for
this issue please.

Thanks in advance
Sudhakar



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Romain Manni-Bucau
2018-07-19 15:10:36 UTC
Permalink
Hi Sudhakar,

Ensure you have a @JohnzonIgnore on one side to avoid a loop.

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>
Post by sudhakarvm
I am facing problem while json is generated from my JPA model object using
default JSON provider Johnzon.
this Johnzon is going in infinite loop to prepare the json and I am getting
/Caused by: javax.json.stream.JsonGenerationException: Invalid json
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:437)/
JPA (using eclipselink) is returning correct results. Any suggestions for
this issue please.
Thanks in advance
Sudhakar
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Matthew Broadhead
2018-07-19 17:17:48 UTC
Permalink
Post by Romain Manni-Bucau
Hi Sudhakar,
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>
Post by sudhakarvm
I am facing problem while json is generated from my JPA model object using
default JSON provider Johnzon.
this Johnzon is going in infinite loop to prepare the json and I am getting
/Caused by: javax.json.stream.JsonGenerationException: Invalid json
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:437)/
JPA (using eclipselink) is returning correct results. Any suggestions for
this issue please.
Thanks in advance
Sudhakar
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Romain Manni-Bucau
2018-07-19 17:40:52 UTC
Permalink
1.1 supports reference handling but not the 1.0 of tomee 7.

Le jeu. 19 juil. 2018 19:17, Matthew Broadhead
Post by Romain Manni-Bucau
Post by Romain Manni-Bucau
Hi Sudhakar,
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <
https://github.com/rmannibucau> |
Post by Romain Manni-Bucau
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<
https://www.packtpub.com/application-development/java-ee-8-high-performance
Post by Romain Manni-Bucau
Post by sudhakarvm
I am facing problem while json is generated from my JPA model object
using
Post by Romain Manni-Bucau
Post by sudhakarvm
default JSON provider Johnzon.
Because of
Post by Romain Manni-Bucau
Post by sudhakarvm
this Johnzon is going in infinite loop to prepare the json and I am
getting
Post by Romain Manni-Bucau
Post by sudhakarvm
/Caused by: javax.json.stream.JsonGenerationException: Invalid json
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:437)/
Post by Romain Manni-Bucau
Post by sudhakarvm
JPA (using eclipselink) is returning correct results. Any suggestions
for
Post by Romain Manni-Bucau
Post by sudhakarvm
this issue please.
Thanks in advance
Sudhakar
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Mark Struberg
2018-07-19 19:57:26 UTC
Permalink
Sadly there is no common handling for this in the current spec.
I've already created a ticket [1], but this will only be available as of JakartaEE9.

You should be able to swap out Johnzon-1.0.x with 1.1.8.
Then use the following JsonbConfig and set "johnzon.deduplicateObjects" to true.

Happy to get feedback about this feature!

LieGrue,
strub



[1] https://github.com/eclipse-ee4j/jsonb-api/issues/72
Post by Romain Manni-Bucau
1.1 supports reference handling but not the 1.0 of tomee 7.
Le jeu. 19 juil. 2018 19:17, Matthew Broadhead
Post by Romain Manni-Bucau
Post by Romain Manni-Bucau
Hi Sudhakar,
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <
https://github.com/rmannibucau> |
Post by Romain Manni-Bucau
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<
https://www.packtpub.com/application-development/java-ee-8-high-performance
Post by Romain Manni-Bucau
Post by sudhakarvm
I am facing problem while json is generated from my JPA model object
using
Post by Romain Manni-Bucau
Post by sudhakarvm
default JSON provider Johnzon.
Because of
Post by Romain Manni-Bucau
Post by sudhakarvm
this Johnzon is going in infinite loop to prepare the json and I am
getting
Post by Romain Manni-Bucau
Post by sudhakarvm
/Caused by: javax.json.stream.JsonGenerationException: Invalid json
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:437)/
Post by Romain Manni-Bucau
Post by sudhakarvm
JPA (using eclipselink) is returning correct results. Any suggestions
for
Post by Romain Manni-Bucau
Post by sudhakarvm
this issue please.
Thanks in advance
Sudhakar
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Mark Struberg
2018-07-19 20:03:47 UTC
Permalink
Oh, I just noticed that we also backported this to Johnzon-1.0.1 [1]. So you better use this as you don't need to bother with upgrading the json-p spec to 1.1.

LieGrue,
strub


[1] https://github.com/apache/johnzon/blob/maintenance_1.0.x/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonBuilder.java#L212
Post by Mark Struberg
Sadly there is no common handling for this in the current spec.
I've already created a ticket [1], but this will only be available as of JakartaEE9.
You should be able to swap out Johnzon-1.0.x with 1.1.8.
Then use the following JsonbConfig and set "johnzon.deduplicateObjects" to true.
Happy to get feedback about this feature!
LieGrue,
strub
[1] https://github.com/eclipse-ee4j/jsonb-api/issues/72
Post by Romain Manni-Bucau
1.1 supports reference handling but not the 1.0 of tomee 7.
Le jeu. 19 juil. 2018 19:17, Matthew Broadhead
Post by Romain Manni-Bucau
Post by Romain Manni-Bucau
Hi Sudhakar,
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <
https://github.com/rmannibucau> |
Post by Romain Manni-Bucau
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<
https://www.packtpub.com/application-development/java-ee-8-high-performance
Post by Romain Manni-Bucau
Post by sudhakarvm
I am facing problem while json is generated from my JPA model object
using
Post by Romain Manni-Bucau
Post by sudhakarvm
default JSON provider Johnzon.
Because of
Post by Romain Manni-Bucau
Post by sudhakarvm
this Johnzon is going in infinite loop to prepare the json and I am
getting
Post by Romain Manni-Bucau
Post by sudhakarvm
/Caused by: javax.json.stream.JsonGenerationException: Invalid json
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:437)/
Post by Romain Manni-Bucau
Post by sudhakarvm
JPA (using eclipselink) is returning correct results. Any suggestions
for
Post by Romain Manni-Bucau
Post by sudhakarvm
this issue please.
Thanks in advance
Sudhakar
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
chongma
2018-08-17 19:28:14 UTC
Permalink
i was trying to output some JPA objects to json today. after adding
johnzon.deduplicateObjects = true to system.properties and restarting TomEE
i still get
javax.json.stream.JsonGenerationException: Invalid json
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:454)
at org.apache.johnzon.mapper.Mapper.writeObject(Mapper.java:147)
at uk.me.kissy.sales.dao.LeadScriptDao.marshall(LeadScriptDao.java:435)
is there any way to get a deeped debug?



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Romain Manni-Bucau
2018-08-17 19:56:36 UTC
Permalink
Do you have a valid equals/hashcode?
Post by chongma
i was trying to output some JPA objects to json today. after adding
johnzon.deduplicateObjects = true to system.properties and restarting TomEE
i still get
javax.json.stream.JsonGenerationException: Invalid json
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:454)
at org.apache.johnzon.mapper.Mapper.writeObject(Mapper.java:147)
at
uk.me.kissy.sales.dao.LeadScriptDao.marshall(LeadScriptDao.java:435)
is there any way to get a deeped debug?
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Matthew Broadhead
2018-08-17 20:05:53 UTC
Permalink
no.  i will add those and try again.

i also changed the entry in system.properties to
org.apache.johnzon.deduplicateObjects = true to match
org.apache.johnzon.max-string-length = 8192
Post by Romain Manni-Bucau
Do you have a valid equals/hashcode?
Post by chongma
i was trying to output some JPA objects to json today. after adding
johnzon.deduplicateObjects = true to system.properties and restarting TomEE
i still get
javax.json.stream.JsonGenerationException: Invalid json
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:454)
at org.apache.johnzon.mapper.Mapper.writeObject(Mapper.java:147)
at
uk.me.kissy.sales.dao.LeadScriptDao.marshall(LeadScriptDao.java:435)
is there any way to get a deeped debug?
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Matthew Broadhead
2018-08-17 20:18:21 UTC
Permalink
is there an annotation which will tell johnzon to return only the id of
the jpa object and not the whole thing?
no. i will add those and try again.
i also changed the entry in system.properties to
org.apache.johnzon.deduplicateObjects = true to match
org.apache.johnzon.max-string-length = 8192
Post by Romain Manni-Bucau
Do you have a valid equals/hashcode?
i was trying to output some JPA objects to json today.  after adding
johnzon.deduplicateObjects = true to system.properties and
restarting TomEE
i still get
javax.json.stream.JsonGenerationException: Invalid json
         at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:454)
         at
org.apache.johnzon.mapper.Mapper.writeObject(Mapper.java:147)
         at
uk.me.kissy.sales.dao.LeadScriptDao.marshall(LeadScriptDao.java:435)
is there any way to get a deeped debug?
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Romain Manni-Bucau
2018-08-17 20:38:30 UTC
Permalink
You can implement a custom converter/adapter to do that

Le ven. 17 août 2018 22:18, Matthew Broadhead
Post by Matthew Broadhead
is there an annotation which will tell johnzon to return only the id of
the jpa object and not the whole thing?
no. i will add those and try again.
i also changed the entry in system.properties to
org.apache.johnzon.deduplicateObjects = true to match
org.apache.johnzon.max-string-length = 8192
Post by Romain Manni-Bucau
Do you have a valid equals/hashcode?
Post by chongma
i was trying to output some JPA objects to json today. after adding
johnzon.deduplicateObjects = true to system.properties and
restarting TomEE
i still get
javax.json.stream.JsonGenerationException: Invalid json
at
org.apache.johnzon.core.JsonGeneratorImpl.close(JsonGeneratorImpl.java:454)
Post by Romain Manni-Bucau
Post by chongma
at
org.apache.johnzon.mapper.Mapper.writeObject(Mapper.java:147)
at
uk.me.kissy.sales.dao.LeadScriptDao.marshall(LeadScriptDao.java:435)
is there any way to get a deeped debug?
--
http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Loading...