On 2021-09-11T21:19:15 -0700
Tatu Saloranta <t...@fasterxml.com> wrote:
>
> The main (or initial?) problem here is just that type LocationID is
> taken to be a POJO with properties (since Records by definition are),
> instead of something behaving like String value. The issue is that
> POJOs cannot be serialized as attributes but only as elements.
> In theory it is possible to annotate Records to work like Strings,
> too, but it might be easier to first try to create equivalent "simple"
> pojo with
> something like:
> 
> static class LocationId {
>    private UUID id;
> 
>    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
>    public LocationId(UUID id) { this.id = id; }
> 
>    @JsonValue // method name can be anything
>    protected UUID id() { return id; }
> }
> 
> which should then serialize as a basic String value, and deserialized
> similarly from a String value.

It works! Thank you!

Will records get some kind of special handling post JDK 17? I often use
these kind of wrappers for extra type safety, and it's a shame that
they can't be expressed as records in this case.

-- 
Mark Raynsford | https://www.io7m.com

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/20210912082957.5c6dd0f2%40sunflower.int.arc7.info.

Attachment: pgpYOMfz0Tc9H.pgp
Description: OpenPGP digital signature

Reply via email to