JaxB cannot be cast to java.lang.Integer -
i have abstract class:
@mappedsuperclass public abstract class baseentity<k> { @temporal(value = temporaltype.timestamp) private date cadastrado; @temporal(value = temporaltype.timestamp) private date modificado; @column(length = 30) private string ip; private string autormodificacao; public abstract k getid(); public abstract void setid(k id); ...
and derived class:
@xmlrootelement @xmlaccessortype(xmlaccesstype.field) public class pessoa extends baseentity<integer> implements serializable { @id @columngridpf @generatedvalue(strategy = generationtype.auto, generator = "pessoa") private integer id; .... @override integer getid() { return id; } @override public void setid(integer id) { this.id = id; } ....
when application try unmarshall object, error
**
severe: runtimeexception not mapped response, re-throwing http container java.lang.classcastexception: com.sun.org.apache.xerces.internal.dom.elementnsimpl cannot cast java.lang.integer @ br.com.sigmaonline.entity.cadastro.pessoa.pessoa.setid(pessoa.java:46) @ br.com.sigmaonline.entity.common.generic.baseentity$jaxbaccessorm_getid_setid_java_lang_object.set(methodaccessor_ref.java:60)
**
can 1 me?
by default when jaxb (jsr-222) implementation creating metadata pessoa going create metadata super class baseentity. since jaxb default considers properties mapped going consider has property called id of type object. when jaxb doesn't know type of property convert dom element. resulting in classcastexception.
solution
the solution depends upon whether or not want baseentity considered part of inheritance hierachy (see: http://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html). recommend either leveraging @xmltransient or @xmlaccessortype(xmlaccesstype.none) on basetype remove problematic properties:
Comments
Post a Comment