Configuring customer serializer via ObjectMapper

22 views
Skip to first unread message

Sasa Vilic

unread,
Oct 14, 2021, 10:40:02 PM10/14/21
to jackson-user
Hi,

is there a way to pass configuration to customer serializer, for given ObjectMapper instance?

Background:

I have created custom UUID serializer/deserializer with idea that I want support both legacy/hex format and advanced efficient format in form of array of 2 long values (MSB and LSB).

My deserializer can read both format, based whenever first token is ARRAY_START or not.

But I have issue with configuring serializer. It only writes in hex format and I would like to configure it differently for particular ObjectMapper instance (when I know it is safe to used advanced format).

But I can't figure out how to pass configuration to serializer? Another option would be to override some configuration about types (i.e. UUID class) but I can't find way either to do it.

Do you have any suggestion?

Kind Regards
Sasa Vilic

Tatu Saloranta

unread,
Nov 10, 2021, 6:34:19 PM11/10/21
to jackson-user
Slow reply, but...

I am not sure what you are asking? When registering your custom serializer via ObjectMapper, you will pass the specifically configured instance.
Or are you using annotations (`@JsonSerialize`)?

If the question is about how to change settings based on things, you may want to look into implementing `ContextualSerializer`: this method gets called with information on what property serializer is going to be used on -- and this gives access to annotations for the property (or detecting case of "root value", not referenced via property).

-+ Tatu +-

 

Kind Regards
Sasa Vilic

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/8686c426-7941-475d-aaf0-4be61f8e4798n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages