I have an XML schema (.xsd file) from which I'm generating Java classes using JAXB. For many of the generated classes there are associated functions. For example, for generated class Dog
there would be a function public static void bark(Dog)
, and for generated class Cat
there would be a function public static void meow(Cat)
.
This feels weird in an object-oriented language like Java. What I would like would be to unmarshall XML into objects that include useful and relevant functionality rather than just being structs.
So if the generated classes are in package gen
then I would have a different package with these classes:
public class Cat extends gen.Cat {
public void meow() { ... }
}
public class Dog extends gen.Dog {
public void bark() { ... }
}
Is there some way to unmarshall into these more-capable subclasses rather than into the gen.*
classes?