-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@JsonTypeInfo property always serialized before other properties #250
Comments
First things first: I think that solution to your problem of whether type id is metadata (default: no property -- much more logical to me, from Object perspective; type is not data) or regular data (exposed as property; explicit type discriminator); I think you can use
to do this. Property was added to exposing type ids more as regular properties. Let me know if that works. As to decision to force outputting of type id (and actually, object id, if any, before it), as the first property by default is a fundamental low-level decision and I am unlikely to change that. Note that performance implications are not trivial for cases of deeply nested structures, because of additional buffering needed, even if they may be for small objects. Unfortunately there is no (efficient) way to know effects a priori. However: for specific case of ordering when type id property is included in explicit ordering, yes, I think this is a reasonable request, and I can see if that can be implemented. The main challenge is that since handling of type id is separate from handling of regular properties, it may be difficult to actually change this (that is: type serializer is called before serializer for properties). |
Actually, come to think of it: it may be impossible to change ordering for type identifier. This because it is serialized first, separate from properties; so code that sorts properties won't have access to it. |
I take the point regarding type id being metadata. You are completely correct, it's redundant metadata once you have concrete class to do an
This ticket is about formalising that prior understanding (and documenting the performance implications) into JsonTypeInfo.As.EXISTING_PROPERTY. The only hitch is that, to do the job properly, I imagine Jackson should still execute the |
In relation to #263, I think that EXISTING_PROPERTY overrides visible=false. It would also change the handling of visible=true as we would not want to ignore the field during property serialisation since we are already ignoring it during type serialisation. |
Ah ok. So, EXISTING_PROPERTY could basically instruct I think I finally got it now that I had time to re-read description. |
You released the annotation without the implementation :)
|
Right, it was added for 2.3, and at this point is waiting for code to add support for it. Hence this issue is open, but annotation one closed. Not optimal situation I know. :) |
So....I just found this annotation, and got that error. Was/Is there an implementation planned? |
@aaronkorver Yes, we still intend to implement support for this value. But when this happens is an open question, so there is no firm version/date. |
Considering this a dup for #528, which will cover adding support for |
If using an existing property as a polymorphic discriminator, I don't want to change the ordering of the generated output but it always appears first.
The below (Jackson 2.2.1) serializer test fails with:
Given there are minor performance implications of having it "somewhere" in the message no one wants this as default behaviour. I think what it comes down to is that lack of something like
JsonTypeInfo.As.EXISTING_PROPERTY
instead of just using@JsonIgnore
on the real property and letting the type system place it at the beginning.As.EXISTING_PROPERTY
would explicitly ignore setting of the type field during serialisation and allow the normal serialisation code to populate it as per the rest of the mapper's configuration. It might want to assert that it is set (to the correct value) but I have not thought this aspect through.FYI, I hacked the above solution by defining the following
@JsonTypeResolver
:The text was updated successfully, but these errors were encountered: