我有一组相当大的 XSD 文件。由此我正确生成了 Java 类(我使用的是 org.apache.cxf.cxf-xjc-plugin
)。我的问题是我从 Web 服务获得的响应不使用命名空间(显然我无法要求服务提供者更改响应)。因此,我使用 jaxb 的解码步骤无法填充内部对象字段。
我用来解码的代码是(类似于)这个:
private <T> T unmarshalFromStr(String str, Class<T> clazz) throws JAXBException {
jaxbCtx = JAXBContext.newInstance(MyGneratedClass1.class, MyGneratedClass2.class, ...);
Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
JAXBElement<T> obj = unmarshaller.unmarshal(new StreamSource(new StringReader(str)), clazz);
return obj.getValue();
}
我(显然)不想重写 xsd 文件或手动修改生成的类。任何提示?
提前致谢。
最佳答案
关于java - 从 XSD 删除命名空间引用生成类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65977526/