On Wed, Oct 12, 2022 at 8:32 PM Tore Petersen
<tore.angell.peter...@gmail.com> wrote:
>
> Hi,
>
> My project is using record as keys for several different maps currently.
> We are sending these maps over json and in testing we found that we needed a 
> spesific keyDeserializer and I needed to make an ugly keyDeserializer:
>
> module.addKeyDeserializer(FrequencyKey.class, new KeyDeserializer() {
>  @Override
>  public FrequencyKey deserializeKey(String key, DeserializationContext ctxt) 
> throws   IOException {
>   return new FrequencyKey(
>    PriceObject.valueOf(key.split(",")[0].split("=")[1]),
>    LocalDate.parse(key.replace("]","").split(",")[1].split("=")[1]));
>  }
> });
>
> And I would like to not have to make one like this for every Record that we 
> use for keys.
> It seems like serializing goes just fine and it produce this string for the 
> record:
> {
>  "FrequencyKey[priceObject=LED_INTR_ODR, validFrom=2021-11-02]": {
>   "id": 12349
>  }
> }
>
> Anyone that could help me in the correct direction for this?

Jackson provides a small set of default KeyDeserializers (and
serializers) out of the box, but they tend to be for scalar values.
Structured types (like POJOs, Collections etc) are not supported both
since they were less commonly used as keys and since there
is no obvious simple way to express these as simple String (but many
possible ways to define a "sub-format" as in your case).

So what you are doing is probably a good way to go about it. If you
can think of a general way we are always open to PRs,
of course. And maybe others have some ideas to share wrt how you go about it.

-+ Tatu +-

-- 
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/CAL4a10g58%2Bq_gUpt2BG%3DTy0wCKGu3DrpKV4fpsa%2BwKYQ6yjQkA%40mail.gmail.com.

Reply via email to