What causes SAXException2: Instance of “com.foo.Bar” is substituting “java.lang.Object”, but “com.foo.Bar” is bound to an anonymous type [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 03:49:07

问题


Migrating existing jaxb (uses both jaxb1.0.1 and jaxb 2.0.5) application (on JBoss 4.3 with jdk5) to jaxb 2.1.10 (supplied with jdk6, update jdk1.6.0_30).

I cannot modify the customer-provided schema.

I have removed all references of jaxws20, jwsdp, jaxp and jaxb jars from Sun RI and am using jars provided by jdk 6 only.

Any pointers ??

Caused by: com.sun.istack.SAXException2: Instance of “com.foo.Bar” is substituting “java.lang.Object”, but “com.foo.Bar” is bound to an anonymous type com.foo.Bar@a2e3ss
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:247)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:662)
at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:165)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:152)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:332)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:698)
at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:152)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:332)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:592)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:320)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:493)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:325)

回答1:


This can be caused by adding Foo objects to a List<Bar> type SOAP parameter.

I had this exact same exception a couple of weeks ago. I would have expected a compilation error, so there must have been some ugly type coercion under the hood to allow it to happen. I didn't investigate any further - replacing Foo's with Bar's (which they should have been anyway) fixed the problem.



来源:https://stackoverflow.com/questions/9131730/what-causes-saxexception2-instance-of-com-foo-bar-is-substituting-java-lang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!