Re: UUID JSON serialization issue

Markus Jung <[email protected]> Fri, 4 Apr 2025 17:33:38 +0200
Newsgroups gmane.comp.java.openejb.user
Message-ID <[email protected]>
Hi,

UUID is not required to be supported by the JSON-B spec =
(https://jakarta.ee/specifications/jsonb/3.0/jakarta-jsonb-spec-3.0#defaul=
t-mapping), so Johnzon does not implement it. As far as I can tell from =
skimming over filenames in yasson it seems like they do however support =
it, hence your example works everywhere else (AFAIK TomEE is the only =
application server that uses Johnzon)

You need to create a JsonbAdapter for this to reliably work and register =
it either globally in JAX-RS with a ContextResolver<Jsonb> (this could =
cause issues e.g. in tests/when you use the models outside of JAX-RS) or =
use it in your model classes with @JsonbTypeAdapter which is what I =
would prefer


Thanks

Markus

> On 4. Apr 2025, at 16:35, hantsy bai <[email protected]> wrote:
>=20
> Hi
> Special thanks to Richard Zowalla for helping me resolve some issues =
of the
> TomEE and Aruqillian configuration.
>=20
> Another issue I found in the Github actions log is the serialization =
issue
> of UUID, TomEE used Apache Johnzon as JSON-B implementation.
>=20
> ```
> Caused by: jakarta.json.bind.JsonbException: Todo property 'id' of =
type ID
> cannot be mapped to json object value:
> {"leastSignificantBits":-5668611215224300934,"most...
> UUID has no suitable constructor or factory. Cannot deserialize json =
object
> value: {"leastSignificantBits":-5668611215224300934,"most...
> Use Johnzon @ConstructorProperties or @JsonbCreator if constructor
> arguments are needed
> class java.util.UUID not instantiable
> at =
org.apache.johnzon.jsonb.JohnzonJsonb.fromJson(JohnzonJsonb.java:253)
> at
> =
org.glassfish.jersey.jsonb.internal.JsonBindingProvider.readFrom(JsonBindi=
ngProvider.java:91)
>=20
> ... 58 more
> ```
>=20
> Check the complete log here:
> =
https://github.com/hantsy/jakartaee10-starter-boilerplate/actions/runs/142=
33160351/job/39887609042#step:4:1657
>=20
> Do we need extra configuration to enable UUID support in Johnzon?
>=20
> ---
>=20
> Regards,
>=20
> *Hantsy Bai*
>=20
> Self-employed consultant, fullstack developer, agile coach,
> freelancer/remote worker
>=20
> GitHub: https://github.com/hantsy
>=20
> Twitter: https://twitter.com/@hantsy
> Medium: https://medium.com/@hantsy