| 1 | JaxB is very troublesome when it comes to template classes and abstract classes. |
| 2 | The main problems are serializations containing xsi and xmlns annotations. Such annotations make the xml unreadable and rigid (resisting future changes). |
| 3 | |
| 4 | List (java.util) combined with abstract classes can be made to work, with a number of annotations. Assume class X is an abstract class with X1 and X2 as implementations. |
| 5 | |
| 6 | Then |
| 7 | * annotate all occurences List<X> with @XmlElementRef |
| 8 | * add @XmlSeeAlso({X1.class, X2.class}) to the X class |
| 9 | * annotate X1 and X2 with @XmlRootElement (and maybe give it a nicer name there too) |
| 10 | |
| 11 | General templates like Myclass<T extends Object> do not serialize nicely. This is because erasure causes the class to serialize 'Object' and deserializing 'Object' will probably result in xsi stuff. |
| 12 | What you can do is to do |
| 13 | |
| 14 | * Myclass<T extends X> |
| 15 | * handle all serialization in class X (not in the T classes) |
| 16 | |
| 17 | This means that you can't have class-specific deserializations. |
| 18 | Maybe you can combine this with the tricks used with List (see above), I never figured this out |