[ 
https://issues.apache.org/jira/browse/JOHNZON-335?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17279120#comment-17279120
 ] 

Trevor Kerby commented on JOHNZON-335:
--------------------------------------

Hello Manni-Bucau

Thank you for the quick responses and implementation of a work around - it's 
very much appreciated, along with all the other times I see your name while 
looking for solutions to TomEE related problems. I wasn't sure exactly what you 
meant by reversing the statements, but I tried flipping the order which I made 
the calls, and I tried out the more typical route of using annotations to drive 
the serialization, but I got the same exception, and I couldn't get the output 
that I'm looking for, respectively. 

I see the test and it runs well on my end. Again, thank you - I'm going to test 
it out with some code I wrote that depends on this feature. I do have a few 
questions if you don't mind:

How do I build Johnzon from source? I seem to be missing some plugins that seem 
to require some authentication.
Secondly, how can I help contribute to this project?

> JsonGeneratorImpl.prepareValue throws JsonGenerationException when 
> JsonGenerator.write is called from a nested JsonbSerializer
> ------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: JOHNZON-335
>                 URL: https://issues.apache.org/jira/browse/JOHNZON-335
>             Project: Johnzon
>          Issue Type: Bug
>          Components: JSON-B
>    Affects Versions: 1.2.9, 1.2.10
>            Reporter: Trevor Kerby
>            Priority: Major
>         Attachments: JohnzonNestedSerializerTest.java
>
>
> When using two JsonbSerializers registered in JsonbConfig, with one 
> serializer - the _outer serializer_ - calling SerializationContext.serialize 
> on an object annotated to be serialized with the other serializer - the 
> _inner serializer_ - Johnzon fails to write the expected json and throws a 
> JsonGenerationException. This seems to happen upon any JsonGenerator.write 
> method called inside the _inner serializer_.
> {code:java}
>       public static class OuterTestSerializer implements 
> JsonbSerializer<OuterTestModel> {
>               @Override
>               public void serialize(OuterTestModel obj, JsonGenerator 
> generator, SerializationContext ctx) {
>                       generator.writeStartObject();
>                       generator.write("foo", "generated in outer serializer");
>                       ctx.serialize("inner", new InnerTestModel(), generator);
>                       generator.writeEnd();
>               }
>       }
>       public static class InnerTestSerializer implements 
> JsonbSerializer<InnerTestModel> {
>               @Override
>               public void serialize(InnerTestModel obj, JsonGenerator 
> generator, SerializationContext ctx) {
>                       generator.writeStartObject();
>                       generator.write("bar", "generated in inner serializer");
>                       generator.writeEnd();
>               }
>       }
> {code}
> Below is the formatted version of the json that's expected
> {code:json}
> {
>     "foo": "generated in outer serializer",
>     "inner": 
>     {
>         "bar": "generated in inner serializer"
>     }
> }
> {code}
> However Johnzon throws this expection
> {code}
> javax.json.stream.JsonGenerationException: state IN_OBJECT does not accept a 
> value
>       at 
> org.apache.johnzon.core.JsonGeneratorImpl.prepareValue(JsonGeneratorImpl.java:643)
>       at 
> org.apache.johnzon.core.JsonGeneratorImpl.writeStartObject(JsonGeneratorImpl.java:137)
>       at 
> org.apache.johnzon.mapper.DynamicMappingGenerator$InObjectOrPrimitiveJsonGenerator.writeStartObject(DynamicMappingGenerator.java:109)
>       at 
> org.apache.johnzon.mapper.DynamicMappingGenerator$InObjectOrPrimitiveJsonGenerator.ensureStart(DynamicMappingGenerator.java:99)
>       at 
> org.apache.johnzon.mapper.DynamicMappingGenerator$InObjectOrPrimitiveJsonGenerator.writeStartObject(DynamicMappingGenerator.java:106)
>       at 
> usa.kerby.tk.jhal.JohnzonNestedSerializerTest$InnerTestSerializer.serialize(JohnzonNestedSerializerTest.java:55)
>       at 
> usa.kerby.tk.jhal.JohnzonNestedSerializerTest$InnerTestSerializer.serialize(JohnzonNestedSerializerTest.java:52)
>       at 
> org.apache.johnzon.jsonb.JohnzonBuilder.lambda$null$24(JohnzonBuilder.java:313)
>       at 
> org.apache.johnzon.mapper.MappingGeneratorImpl.writeObject(MappingGeneratorImpl.java:97)
>       at 
> org.apache.johnzon.mapper.DynamicMappingGenerator.writeObject(DynamicMappingGenerator.java:53)
>       at 
> org.apache.johnzon.jsonb.serializer.JohnzonSerializationContext.serialize(JohnzonSerializationContext.java:36)
>       at 
> usa.kerby.tk.jhal.JohnzonNestedSerializerTest$OuterTestSerializer.serialize(JohnzonNestedSerializerTest.java:46)
>       at 
> usa.kerby.tk.jhal.JohnzonNestedSerializerTest$OuterTestSerializer.serialize(JohnzonNestedSerializerTest.java:41)
>       at 
> org.apache.johnzon.jsonb.JohnzonBuilder.lambda$null$24(JohnzonBuilder.java:313)
>       at 
> org.apache.johnzon.mapper.MappingGeneratorImpl.doWriteObject(MappingGeneratorImpl.java:174)
>       at org.apache.johnzon.mapper.Mapper.writeObject(Mapper.java:235)
>       at 
> org.apache.johnzon.mapper.Mapper.writeObjectWithGenerator(Mapper.java:208)
>       at org.apache.johnzon.mapper.Mapper.writeObject(Mapper.java:203)
>       at org.apache.johnzon.mapper.Mapper.writeObjectAsString(Mapper.java:252)
>       at org.apache.johnzon.jsonb.JohnzonJsonb.toJson(JohnzonJsonb.java:268)
>       at 
> usa.kerby.tk.jhal.JohnzonNestedSerializerTest.testNestedSerializer(JohnzonNestedSerializerTest.java:28)
> {code}
> Tested against Yasson 1.0.8, Johnzon 1.2.9, and Johnzon 1.2.10. Yasson 
> produces the expected JSON. Am I right in thinking this is a bug? 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to