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

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


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.