Hi Xavier, Think you are right, have to admit I always use adapters so didn't spot this one:
public static class UUIDAdapter implements JsonbAdapter<UUID, String> { @Override public String adaptToJson(UUID obj) throws Exception { return obj.toString(); } @Override public UUID adaptFromJson(String obj) throws Exception { return UUID.fromString(obj); } } Will have a quick look this afternoon. The only tests we have for serializers are to serialize another object which works but map an object to a primitive is not supported for now. 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 à 13:50, 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 or am I doing something wrong? > > Regards, > Xavier >