java - How to Have Spring Pass Subclasses to Creation of JAXBContext? -
my problem solved @xmlseealso, can't in case because child , super class in 2 different projects.
parent project - abstractparent ( property = commonproperty ) - wrapperobject ( property = abstractparent, other properties ) child project - includes parent project - conceretechild extends abstractparent ( property = extraproperty ) service project - includes parent project , child project
service project spring-based project uses httpmessageconverter defined in applicationcontext.xml - in org.springframework.oxm.jaxb.jaxb2marshaller bean instantiation, used "packagestoscan" property , include both abstractparent package , concretechild package.
service project instantiate concretechild , put wrapperobject returned controller class , let spring message converter convert xml.
my problem: when spring object conversion on wrapperobject, sees abstractparent properties, not see concretechild properties @ all.
this solved @xmlseealso on abstractparent, because parent project not include (and cannot include) child project, can't make use of @xmlseealso. including child project parent project create cycle.
is there way around this?
update
all threads found talk adding @xmlseealso - again, impossible me because parent , subclass in 2 different projects.
i tested with:
class[] cs = new class[2]; cs[0] = concretechild.class; cs[1] = wrapperobject.class; jaxbcontext context = jaxbcontext.newinstance(cs); marshaller marshaller = context.createmarshaller(); bytearrayoutputstream baos = new bytearrayoutputstream(); marshaller.marshal(responsedto, baos); string xmlstr= new string(baos.tobytearray());
and above code works fine, resulting "xmlstr" produces approppriate xml concretechild (instead of abstractparent). resulting xml has xsi:type specify conretechild
i have retrieve jaxb2marshaller spring context , print out list of classes bound marshaller, , included concretechild - resulting xml spring's httpmessageconverter still ignores it, includes abstractparent - , doesn't have xsi:type.
so weird going on jaxb processing done spring?
additionally - tried removing values packagestoscan on jaxb configuration in spring applicationcontext.xml - complain packagestoscan cannot empty (expected behaviour), add string value pointing package has nothing objects: wrapperobject / abstractparent / concretechild - magically, spring http message converter still works !
so really, there's weird http message conversion spring?
Comments
Post a Comment