On Thu, Nov 30, 2017 at 10:34 AM,  <[email protected]> wrote:
> Hi all,
>
> I'm using jackson to serialize POGOs (Groovy POJO) to and from json. By
> default, jackson will start at the top of the inheritance tree and output
> the values in order of the inheritance. Unfortunately, the base class that
> all of my POGOs extend from contains the variables that should be displayed
> last. Additionally, the direct parent class should still be displayed before
> the child class. Is there any way to define the order in which the inherited
> classes are displayed in the output?

The main mechanism for changing serialization order is by using
`@JsonPropertyOrder` annotation,
or, for custom ordering, method in `AnnotationIntrospector` that
normally reads and uses that
annotation. There is no way to configure handling with respect to
inheritance order.

-+ Tatu +-

>
>
> Example:
>
> These variables should be displayed last.
>
> class BaseEntity
> {
>   String createUser;
>   Date createDate;
>   String updateUser;
>   Date updateDate;
>   int version = 0;
>
>
>   ...
>
> }
>
>
> These variables should be displayed first.
>
> class DatastoreEntity<T extends DatastoreEntity> extends BaseEntity
> implements Cloneable
> {
>   @Id
>   Long id;
>
>   @Ignore
>   @JsonIgnore
>   T original;
>
>
>   ...
>
> }
>
>
> These variables should be displayed between the other two.
>
> @Entity
> public class Person extends DatastoreEntity<Person>
> {
>
>   @Index
>   String firstName;
>
>   @Index
>   String lastName;
>
>   @Index
>   int age;
>
>   @Index
>   String gender
> }
>
>
> Current Output:
>
> {
>     "createUser": "[email protected]",
>     "createDate": 1512064212616,
>     "updateUser": "[email protected]",
>     "updateDate": 1512064212616,
>     "version": 1,
>     "id": 5717271485874176,
>     "firstName": "Steve",
>     "lastName": "Johnson",
>     "age": 30,
>     "gender": "male"
> }
>
> Desired Output:
> {
>     "id": 5717271485874176,
>     "firstName": "Steve",
>     "lastName": "Johnson",
>     "age": 30,
>     "gender": "male",
>     "createUser": "[email protected]",
>     "createDate": 1512064212616,
>     "updateUser": "[email protected]",
>     "updateDate": 1512064212616,
>     "version": 1
> }
>
> --
> 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