java - JAXB attribute with Object type throwing null pointer exception? -
i trying annotate java class create jaxb schema element has attribute of value. code below:
@xmlattribute(name="value") public object getsettingvalue() { homecoming this.settingvalue; } public void setsettingvalue( final object settingvalue ) { this.settingvalue = settingvalue; }
when seek generate schema (using eclipse's non-moxy implementation), null pointer exception:
exception in thread "main" java.lang.nullpointerexception @ com.sun.xml.internal.bind.v2.runtime.reflect.transducedaccessor.get(transducedaccessor.java:154) @ com.sun.xml.internal.bind.v2.runtime.property.attributeproperty.<init>(attributeproperty.java:56) @ com.sun.xml.internal.bind.v2.runtime.property.propertyfactory.create(propertyfactory.java:93) @ com.sun.xml.internal.bind.v2.runtime.classbeaninfoimpl.<init>(classbeaninfoimpl.java:145) @ com.sun.xml.internal.bind.v2.runtime.jaxbcontextimpl.getorcreate(jaxbcontextimpl.java:479) @ com.sun.xml.internal.bind.v2.runtime.jaxbcontextimpl.<init>(jaxbcontextimpl.java:305) @ com.sun.xml.internal.bind.v2.runtime.jaxbcontextimpl$jaxbcontextbuilder.build(jaxbcontextimpl.java:1100) @ com.sun.xml.internal.bind.v2.contextfactory.createcontext(contextfactory.java:143) @ com.sun.xml.internal.bind.v2.contextfactory.createcontext(contextfactory.java:110) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) @ java.lang.reflect.method.invoke(method.java:597) @ javax.xml.bind.contextfinder.newinstance(contextfinder.java:202) @ javax.xml.bind.contextfinder.find(contextfinder.java:376) @ javax.xml.bind.jaxbcontext.newinstance(jaxbcontext.java:574) @ javax.xml.bind.jaxbcontext.newinstance(jaxbcontext.java:522) @ org.eclipse.jpt.jaxb.core.schemagen.main.buildjaxbcontext(main.java:95) @ org.eclipse.jpt.jaxb.core.schemagen.main.generate(main.java:76) @ org.eclipse.jpt.jaxb.core.schemagen.main.execute(main.java:62) @ org.eclipse.jpt.jaxb.core.schemagen.main.main(main.java:47)
when made @xmlelement instead of attribute, schema generated no issues, must have that. ideas?
the nullpointerexception
seeing appears due bug in jaxb reference implementation. can come in bug using next link.
a similar exception not occur when using eclipselink jaxb (moxy) jaxb provider.
workaround
you alter property of type string
instead. property of type object
not round trip anyways unlike elements, attributes not have mechanisms include typing information.
when made @xmlelement instead of attribute, schema generated no issues, must have that.
java model (root)
object valid property type when mapped xml element.
import javax.xml.bind.annotation.xmlrootelement; @xmlrootelement public class root { private object settingvalue; public object getsettingvalue() { homecoming settingvalue; } public void setsettingvalue(final object settingvalue) { this.settingvalue = settingvalue; } }
this because xml element can contain typing info in form of xsi:type
attribute.
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <root> <settingvalue xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xs="http://www.w3.org/2001/xmlschema" xsi:type="xs:int">123</settingvalue> </root>
java jaxb
No comments:
Post a Comment