5

I have a structure like

public class Grandpa...

public class Father extends Grandpa...

public class Son extends Father...

I want to marshall it to file with propOrder annotation.

So i can use @XmlTransient on Grandpa and set propOrder on Father class, but How can i apply propOrder to all 3 classes?

As i understand '@XmlTransient'-approach is only for one super class, and one child class?

Eugene Kisly
  • 129
  • 12

1 Answers1

4

When you specify @XmlTransient on a class as far as JAXB is concerned you remove it from the inheritance hierarchy and its properties are considered part of its children. This means if you mark Father as transient you can include its properties in the propOrder for Son. If you mark Grandpa and Father as transient then you could include the properties from both classes in the propOrder for Son.

Without @XmlTransient you can still use propOrder, but in that propOrder you can only specify the properties that correspond to that class. This corresponds to the ordering of elements that occurs with extended complex types, inherited properties appear first.

For More Information

bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Thanks! I read a lot of your articles before asking :) "If you mark Grandpa and Father as transient then you could include the properties from both classes in the propOrder for Son." but in this case and can't use proporder on Father object, and on Grandpa object? So in this case i can just order fields of instances of Son class? – Eugene Kisly Dec 16 '13 at 18:15
  • @EugeneKisly - That's correct. Is that the behaviour you are looking for? – bdoughan Dec 16 '13 at 18:17
  • No, i am looking for ordering properties in Father objects, Grandpa objects, and Son objects. – Eugene Kisly Dec 16 '13 at 18:18
  • @EugeneKisly - You want a property from `Grandpa` to appear in different relative positions in the `Father`, `Grandpa`, and `Son` objects? – bdoughan Dec 16 '13 at 18:20
  • Yes, for example i want to order properties in GrandPa objects, but also i want to see Son properties not after all GrandPa properties, but mixed with them. Is it possible or not? – Eugene Kisly Dec 16 '13 at 18:23
  • @EugeneKisly - That use case is not possible. – bdoughan Dec 16 '13 at 18:31