I need to map an XML, constrained by an XSD to Java object using XStream. The XSD has 4 complex type elements, which are "choice" elements, that is either one of those 4 can be present in the XML under a root tag.
I have been looking at XStream but it seems to me that, to map such an XML, I would require 8 classes. How? here it is...
Say for example my root element is VEHICLE and each of the complex types in the XML are a) CAR b) BIKE c) TRUCK d) TRACTOR. Each of them have differing properties within them. To map this to Xstream and make the XML (generated by XStream) XSD compliant, we would need 8 classes viz. VehicleCarWrapper -> (has a) Car, VehicleTruckWrapper -> (has a) Truck, VehicleBikeWrapper -> (has a) Bike and VehicleTractorWrapper -> (has a) Tractor.
Does anyone have a suggestion apart from the shabby solution? Is there a way in Xstream to map such a "choice"d element of the XML root? So as that, All the 4 (viz. Truck, Car, Bike, Tractor) can go into the Wrapper as associated entities, but XStream ignores all but one association at all times and hence creates an XSD compliant XML.
Hope my question is clear.
Many thanks!