- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
通常 JAXB 可以工作,但它没有正确解析我的模式,或者它应该将 XMLRootElement 放在我的对象上的东西,但没有。我使用这段代码来解码失败,我不得不求助于将包用作字符串..
ProductsDomainResponseType resp = unmarshaller.unmarshall(ProductsDomainResponseType.class, strXmlInput);
这是xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.cigna.com/acme/services/product/2012/03"
xmlns:prd="http://www.cigna.com/IFPRetail/Product/0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:outc="http://www.cigna.com/acme/domains/utility/outcome/2010/03"
targetNamespace="http://www.cigna.com/acme/services/product/2012/03"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.cigna.com/IFPRetail/Product/0.1" schemaLocation="product.xsd" />
<xs:import namespace="http://www.cigna.com/acme/domains/utility/outcome/2010/03" schemaLocation="InvocationOutcome_2010_03.xsd" />
<xs:element name="productsDomainResponse" type="ProductsDomainResponseType">
<xs:annotation>
<xs:documentation>in case of error use invocationOutcome element from
InvocationOutcome XSD in utility namespace</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="ProductsDomainResponseType">
<xs:annotation>
<xs:documentation>Products Domain XML Response</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element ref="outc:invocationOutcome" />
<xs:element name="products" type="ProductType" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ProductType">
<xs:sequence>
<xs:element ref="prd:product" />
</xs:sequence>
</xs:complexType>
</xs:schema>
最后,我生成的对象缺少 XmlRootElement。知道发生了什么事吗?
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ProductsDomainResponseType", propOrder = {
"invocationOutcome",
"products"
})
public class ProductsDomainResponseType {
最佳答案
我现在正在做的项目中遇到了这个问题。试试下面的方法。特别是最后几行应该会有帮助。
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = post.getResponseBodyAsStream();
Document doc = db.parse(is);
DOMSource ds = new DOMSource(doc);
JAXBContext responseContext = JAXBContext.newInstance(SearchEnrolledFundingResponse.class);
Unmarshaller u = responseContext.createUnmarshaller();
JAXBElement<SearchEnrolledFundingResponse> jaxbResponse = (JAXBElement<SearchEnrolledFundingResponse>) u.unmarshal(ds, SearchEnrolledFundingResponse.class);
SearchEnrolledFundingResponse searchResponse = jaxbResponse.getValue();
关于java - JAXB 返回 JAXBElement 而不是根元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9791992/
以下代码有效: private List custom; @XmlAnyElement public List getCustom() { if (custom == null) {
我有一个使用 Spring (v4.0.5) 的 http 服务。它的 http 端点是使用 Spring Web MVC 配置的。响应是根据模式生成的 JAXB2 注释类。响应被包装在 JAXBEl
我有一个 xsd,其中包含替换组。当我尝试使用 cxf wsdl2java JAXB 生成 Java 类时,生成 List> 而不是 List 。如何避免 JAXBElement?我尝试使用 bind
我想从 XSD 文件生成带有 JAXB 的 Java 类。 问题是,我总是得到一些像这样的类(删除了命名空间): public static class Action { @X
我在用: GSON 2.3.1 apache-cxf-3.1.1 JBoss EAP 6.4 我正在使用 wsdl2java 从 wsdl 创建 webservice 客户端。 我用以下方法生成类:
我有一个完全可用且经过测试的 REST API。我正在使用 enunciate 创建文档。 请求和响应对象是使用 jaxb 从 xsd 文件生成的。在文档中,可以识别响应对象,但我的请求正文类型是(自
我想实现一个返回 JAXBElement 的方法,下面是代码 @XmlRootElement(name = "history") @XmlAccessorType(XmlAccessType.FIEL
我有多个根元素,因此,我需要写 JAXBElement jaxbBookType = objectFactory.createBookType (bookType); JAXBElement jaxb
考虑 JAXB 生成的以下代码: public class CnpOnlineResponse { protected JAXBElement transactionResponse;
我有以下代码, JAXBContext jc = JAXBContext.newInstance(TestResults.class); Marshaller m = jc.createMarshal
当我尝试从 wsdl 文档生成客户端时,我得到的客户端似乎有很多 JAXBElement 属性,例如 protected List> nameOrLinkingNameOrFamilyName; 我使
我正在使用 NetBeans 和 Glassfish 从现有 WSDL 构建 Web 服务。NetBeans 已从给定的 WSDL 创建了所需的类。WSDL 定义了一些基本数据类型(例如 BaseTy
我定义了一个 Book 类,我想创建一个 JAXBElement 对象,该对象将包含与来自 String 对象的 XML 对应的信息。 例如,我可以有这样的东西: String code = "Har
如何编码 JAXBElement 列表? 例如,我有一个无法注释的 POJO: public class APojo { private String aString; public APojo()
我有一个方法 public Response xyz ( JAXBElement request ) { ...... } 两个不同的地方使用不同的 JAXBElement 调用它。一与 xyz(JA
您好,我想将 JAXBelement 值存储到 String 变量,请告诉我该怎么做。我有以下方法。 public JAXBElement getSessionId() { return s
我已经从我的 XML .xsd 生成了类,并且正在尝试设置一个字段 EndpointID在类(class)内MeterSessionInputRF .我遇到的问题是 setEndpointID方法只接
我正在学习 JAX-WS,并且还介绍了 JAXB。我可以用它来将 java(xml) 编码(un)编码为 xml(java)。但是这行代码的目的是什么,然后我使用 Apache CXF 生成了 WS
我有一个关于 JAXB 的简单问题。这是示例代码: //setter that has input JAXBElement b.setBIC(JAXBElement value); 如何初
我有一个名为 MYClass 的类,其代码如下所示 package com.rest; public class MyClass { private String var; publi
我是一名优秀的程序员,十分优秀!