I am using JAXB to generate POJOs from XSDs. Due to some reasons , the generated POJOs have JAXBElement<CustomObject>
as property.
public class ResponsePackageType{
protected JAXBElement<? extends ResponseType> response;
....
}
Multiple classes is extending ResponseType
but I am only interested to map one type of it, and Orika is having problem recognizing this property.
My code:
JAXBElement<ResponsePackageType> feed = (JAXBElement<ResponsePackageType>) unmarshaller.unmarshal(new FileInputStream( "input.xml" ));
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
Type<JAXBElement<ResponsePackageType>> respPackageType = new TypeBuilder<JAXBElement<ResponsePackageType>>(){}.build();
Type<JAXBElement<SpecialResponseType>> spRespType = new TypeBuilder<JAXBElement<SpecialResponseType>>(){}.build();
mapperFactory.classMap(respPackageType, respPackageType)
.fieldMap("response", "response")
.aElementType(spRespType )
.bElementType(spRespType )
.add()
.byDefault().register();
MapperFacade mapper = mapperFactory.getMapperFacade();
mapper.map(feed, objectFactory.createResponsePackage(null));
Exception:
Exception in thread "main" java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
at ma.glasnost.orika.constructor.ConstructorParameterResolver.getProperties(ConstructorParameterResolver.java:73)
at ma.glasnost.orika.constructor.ConstructorParameterResolver.getPossibleConstructorParams(ConstructorParameterResolver.java:119)
at ma.glasnost.orika.property.PropertyResolver.resolveConstructorProperty(PropertyResolver.java:701)
at ma.glasnost.orika.property.PropertyResolver.getProperty(PropertyResolver.java:686)
at ma.glasnost.orika.property.PropertyResolver.getProperty(PropertyResolver.java:616)
at ma.glasnost.orika.metadata.ClassMapBuilder.resolveProperty(ClassMapBuilder.java:828)
at ma.glasnost.orika.metadata.ClassMapBuilder.resolvePropertyForA(ClassMapBuilder.java:838)
at ma.glasnost.orika.metadata.ClassMapBuilder.fieldMap(ClassMapBuilder.java:379)
How do I go about to solve this issue ?? Should I use propertyResolverStrategy ?