Referencing parent values during custom (de)serialization

295 views
Skip to first unread message

Ben Foster

unread,
May 22, 2014, 1:15:41 PM5/22/14
to jackso...@googlegroups.com
Is there currently any way to reference parent objects' property values from within a custom serializer/deserializer?  

For example, given the following structure:

class Parent {
  @SomeAnno1
  String id;
  @SomeAnno2
  Date createDate;
  OtherClass child;
}

class OtherClass {
  @AnnotationToTriggerCustomSerializer
  String value;
}


What I need, is during serialization and deserialization of OtherClass.value, to get the values of parent fields with the @SomeAnno1 and @SomeAnno2 (in this case id and createDate) in order to properly serialize the value.  I do not want to have a custom serializer assigned to Parent.id and Parent.createDate because those fields may already have serializers that I don't want to affect.

I've seen notes about using the new contextual attributes, but haven't been able to get this to actually work for me.  Is this possible?

Thanks!

Tatu Saloranta

unread,
May 22, 2014, 11:31:04 PM5/22/14
to jackso...@googlegroups.com
There is no direct support for this at this point. It would now be possible to add a feature to start passing this information via contextual attributes, but such feature has not yet been implemented. This requires some care just make sure that cost is trivial for case where information is not needed.

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

Reply all
Reply to author
Forward
0 new messages