I filed an issue, thanks for the explanations Tatu.

Dawid

On Sun, Nov 12, 2017 at 5:29 AM, Tatu Saloranta <[email protected]> wrote:
> On Sat, Nov 11, 2017 at 3:40 AM, Dawid Weiss <[email protected]> wrote:
>>> Unfortunately reading/writing Object Id values, references, requires
>>> support by value (de)serializers
>>
>> Thanks Tatu. I sort of figured it out. I also tried to implement
>> serialization inside
>> my own handler based on the infrastructure provided by Jackson
>> (annotations and ObjectIdReader, etc.),
>> but there seemed to be always some piece missing -- browsing through the code
>> those pieces are typically passed around but are not easily provided via the 
>> contexts
>> (serialization or deserialization).
>
> This is quite possible in that access may have been added in a way
> that just supports usage
> via BeanDeserializer/BeanSerializer.
>
>> I also checked the tests, but I didn't find any obvious example there.
>>
>> I would gladly resort to implementing my own id-resolution inside the
>> serializer -- this seems the easiest way to go, actually,
>> but I'd appreciate some help on understanding the lifecycle of the
>> "per-serialization/deserialization" contexts inside the
>> serializer and deserializer so that I can implement in in a nice way.
>
> Ok. So, contexts in question are:
>
> - DeserializationContext for deserialization
> - SerializerProvider for serialization
>
> (latter really should be `SerializationContext`, but that's since
> serialization side was fully develop
> (for something like 0.9.5 :-) ) before tackling deserialization --
> this just for historical interest)
>
> and they are constructed during initialization of `readValue()` /
> `writeValue()` calls by `ObjectMapper`
> (and `ObjectReader` / `ObjectWriter`).
> Both contain attribute context, which you could use for keeping track
> of ids; you do not have to clean
> them up or anything as any values set are just dropped once
> `readValue()`/`writeValue()` call finishes.
>
>> I'll need a per-serialization (or deserialization) bidirectional
>> mapping between object IDs and objects. I can hack this
>> inside the serialize/deserialize methods and lazily check/ create a
>> custom attribute in SerializerProvider and
>> in DeserializationContext. Is there any nicer way of doing this you
>> can thing of?
>
> That sounds like a reasonable approach to me.
>
> If you did want to see how `ObjectIdReader` etc worked, you could
> check `BeanDeserializerBase`
> (from its construction from `BeanDeserializerBuilder` to `createContextual`).
>
> Actually one more thing that might be useful: if you could file an
> issue for `jackson-databind` for
> something like "Please include a test for Object Id handling for a
> custom type", that'd be useful.
> While I can't guarantee I'll do that, it's possible I might -- and I
> do go through issues as sort of
> todo list every now and then. I do think it should be doable and
> documented, even if only via
> unit tests: it is something that should be available for, say,
> datatype libraries.
>
> -+ Tatu +-
>
>>
>> Dawid
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to