-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
property order in subclass #1091
Comments
According to https://stackoverflow.com/questions/17995623/jsonpropertyorder-and-fields-from-the-super-class it looks like it should be ignoring the property order declared in A all together. If that's the case, we may need to update the property order declared in B to enforce that A properties are written before B properties. However, as I'm not particularly savvy with the JSON schema standard, I have to ask whether super class properties preceding subclass properties is part of the standard or is it simply something you'd prefer? How do we know that it should be A->B instead of B->A? In the short term, you can solve the problem using a jackson mixin, but that's understandably not a good solution since it requires you to make mix ins for all of your classes that have inheritance. |
I think it's just a matter of preference, really, so I'm not sure this is even a bug. But I think "superclass properties before subclass" is what makes most sense.
I don't have that many so I might do this as a workaround. |
I could see cases where you would want either one first. I would say most of the time though that I would prefer the super class first then the subclass. The best reason would if the base class defines a id I would like that to be first regardless of which class in the hierarchy is used. I could see the following property order control to be defined:
There is lots of discussion on the json schema project about this and I am not sure if it all resolved at some point. There was talk of moving it to sub-schemas like a json schema for UI. |
Brainstorming of Implementation Types:
|
Do you have a link to this maybe ? I'm surprised this is a concern of the json schema project, as a schema is mainly a definition of validity and we know that in this respect, the order of properties is not relevant. |
Some progress about this: I was set to write a custom annotator to include the parent class properties first in the
By generating a My workaround for this is to use a custom annotator that extends
By systematically using the |
IMO it's great that the generated |
Of course, but if you read all the discussion form the start, you'll see that it's about the order of properties when inheritance is involved. |
Say I have 2 schemas
a.json
andb.json
that generate classesA
andB
.In
b.json
I "inherit"a.json
using the "extends" mechanism.In the generated classes
A
andB
there is aJsonPropertyOrder
annotation that specifies the correct property order; however, when serializing,B
's properties appear beforeA
's properties in the resulting JSON.Is there a way to make Jackson serialize the super class properties before the subclass?
The text was updated successfully, but these errors were encountered: