【发布时间】:2021-05-04 17:36:30
【问题描述】:
我有一组相当大的 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 xml xsd namespaces cxf