Yep, only fixed serializer
Do you want to do a PR for the other side?

Le mar. 2 avr. 2019 à 19:19, Xavier Dury <kal...@hotmail.com> a écrit :

> Hi Romain,
>
> I tested your modification and it's working for serialization but it fails
> for deserialization:
>
>         public static class UUIDSerializer implements
> JsonbSerializer<UUID> {
>                 public void serialize(UUID obj, JsonGenerator generator,
> SerializationContext ctx) {
>                         generator.write(obj.toString());
>                 }
>         }
>
>         public static class UUIDDeserializer implements
> JsonbDeserializer<UUID> {
>                 public UUID deserialize(JsonParser parser,
> DeserializationContext ctx, Type rtType) {
>                         return UUID.fromString(parser.getString());
>                 }
>         }
>
>         public static class UUIDHolder {
>                 @JsonbTypeSerializer(UUIDSerializer.class)
>                 @JsonbTypeDeserializer(UUIDDeserializer.class)
>                 public UUID uuid = UUID.randomUUID();
>         }
>
>         @Test
>         public void testIt() {
>                 Jsonb jsonb = JsonbBuilder.create();
>                 StringWriter w = new StringWriter();
>                 jsonb.toJson(new UUIDHolder(), w);
>                 jsonb.fromJson(w.toString(), UUIDHolder.class);
>         }
>
> java.lang.UnsupportedOperationException: Array handling with
> ObjectConverter currently not implemented
>         at
> org.apache.johnzon.mapper.MappingParserImpl.toValue(MappingParserImpl.java:736)
>         at
> org.apache.johnzon.mapper.MappingParserImpl.buildObject(MappingParserImpl.java:338)
>         at
> org.apache.johnzon.mapper.MappingParserImpl.readObject(MappingParserImpl.java:141)
>         at
> org.apache.johnzon.mapper.MappingParserImpl.readObject(MappingParserImpl.java:133)
>         at
> org.apache.johnzon.mapper.MappingParserImpl.readObject(MappingParserImpl.java:125)
>         at org.apache.johnzon.mapper.Mapper.mapObject(Mapper.java:328)
>         at org.apache.johnzon.mapper.Mapper.readObject(Mapper.java:267)
>         at org.apache.johnzon.mapper.Mapper.readObject(Mapper.java:262)
>         at
> org.apache.johnzon.jsonb.JohnzonJsonb.fromJson(JohnzonJsonb.java:60)
>
> Xavier
>
> ________________________________________
> From: Xavier Dury <kal...@hotmail.com>
> Sent: Tuesday, April 2, 2019 3:46 PM
> To: dev@johnzon.apache.org
> Subject: Re: Possible problem with JsonbSerializer
>
> Hi Romain,
>
> yes it is a duplicate... I sent the first mail before confirming my
> subscription to the mailing list (first time posting) then sent it a second
> time not knowing the first one would be sent anyway after the
> confirmation... sorry about that.
>
> Xavier
>
> ________________________________________
> From: Romain Manni-Bucau <rmannibu...@gmail.com>
> Sent: Tuesday, April 2, 2019 3:17 PM
> To: dev@johnzon.apache.org
> Subject: Re: Possible problem with JsonbSerializer
>
> Hi Xavier,
>
> is it a duplicate - or did I mess up my inbox?
>
> In any case i opened https://issues.apache.org/jira/browse/JOHNZON-207 and
> pushed a first fix if you want to have a look.
>
> 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
> >
>
>
> Le mar. 2 avr. 2019 à 14:00, Xavier Dury <kal...@hotmail.com> a écrit :
>
> > Hi,
> >
> > When trying the following code on Johnzon 1.1.12-SNAPSHOT:
> >
> >     public class UUIDSerializer implements JsonbSerializer<UUID> {
> >         public void serialize(UUID obj, JsonGenerator generator,
> > SerializationContext ctx) {
> >             generator.flush();
> >             System.out.println("!!!");
> >             generator.write(obj.toString());
> >         }
> >     }
> >
> >     public class UUIDHolder {
> >         @JsonbTypeSerializer(UUIDSerializer.class)
> >         public UUID uuid = UUID.randomUUID();
> >     }
> >
> >     JsonbBuilder.create().toJson(new UUIDHolder(), System.out);
> >
> > I get the following printed on System.out:
> >
> >     {"uuid":{!!!
> >
> > and an exception:
> >
> > javax.json.stream.JsonGenerationException: write(param) is only valid in
> > arrays
> >         at
> >
> org.apache.johnzon.core.JsonGeneratorImpl.checkArray(JsonGeneratorImpl.java:623)
> >         at
> >
> org.apache.johnzon.core.JsonGeneratorImpl.write(JsonGeneratorImpl.java:384)
> >         at
> >
> org.apache.johnzon.jsonb.SerializerTest$ConcreteSerializer.serialize(SerializerTest.java:249)
> >         at
> >
> org.apache.johnzon.jsonb.SerializerTest$ConcreteSerializer.serialize(SerializerTest.java:1)
> >         at
> >
> org.apache.johnzon.jsonb.JsonbAccessMode$WriterConverters.lambda$0(JsonbAccessMode.java:793)
> >         at
> >
> org.apache.johnzon.mapper.MappingGeneratorImpl.writeValue(MappingGeneratorImpl.java:381)
> >
> > This looks kinda strange to me because, it seems that Johnzon tries to
> > start a new object (hence the opening bracket in the output in front of
> the
> > '!!!') before it passes control to the serializer. Why does Johnzon do
> > that? The serializer could decide that the object could be stored as an
> > object ({}), an array ([]) or a primitive value.
> >
> > Should I report an issue?
> >
> > Regards,
> > Xavier
>

Reply via email to