简体   繁体   English

JAXB xjc生成字段作为元素列表

[英]JAXB xjc generates fields as a list of elements

I have a problem with the following sequence of a wsdl file wsdl文件的以下顺序出现问题

                <xsd:sequence>
                <xsd:element maxOccurs="1" minOccurs="1" name="allowCaseWithNewContract" type="xsd:boolean">
                </xsd:element>
                <xsd:choice minOccurs="0">
                    <xsd:element name="validationError" type="mnp:ErrorType"/>
                    <xsd:element name="internalError" type="mnp:ErrorType"/>
                    <xsd:element name="businessError" type="mnp:ErrorType"/>
                    <xsd:element name="externalError" type="mnp:ErrorType"/>
                </xsd:choice>
            </xsd:sequence>

            <xsd:sequence>
                <xsd:element maxOccurs="1" minOccurs="1" name="allowCaseWithExistingContract" type="xsd:boolean">
                </xsd:element>
                <xsd:choice minOccurs="0">
                    <xsd:element name="validationError" type="mnp:ErrorType"/>
                    <xsd:element name="internalError" type="mnp:ErrorType"/>
                    <xsd:element name="businessError" type="mnp:ErrorType"/>
                    <xsd:element name="externalError" type="mnp:ErrorType"/>
                </xsd:choice>
            </xsd:sequence>


I tried to use jaxb binding customization : 我试图使用jaxb绑定自定义:

<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
              xmlns:xs="http://www.w3.org/2001/XMLSchema"
              xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
  <jxb:globalBindings>
    <xjc:simple />
  </jxb:globalBindings>
</jxb:bindings>

I'm trying to avoid jaxb - xjc from generating my fields as a List<JAXBElement<?>> validationErrorsAndAllowCaseWithExistingContractsAndInternalErrors , is there anyway I could accomplish that? 我试图避免jaxb-xjc将我的字段生成为List<JAXBElement<?>> validationErrorsAndAllowCaseWithExistingContractsAndInternalErrors ,无论如何我都能做到这一点吗?

I advise you to simplify the schema if possible. 我建议您尽可能简化架构。 I would put the allowCaseWithNewContract and allowCaseWithExistingContract as attributes in the enclosing element. 我将allowCaseWithNewContractallowCaseWithExistingContract作为属性包含在封闭元素中。 I guess then, the remaining choice would have the type ErrorType . 我猜然后,剩下的选择将具有ErrorType类型。

我不允许发表评论,但是我相信这个问题在这里这里都已经得到解决-基本上,您最好的选择是使用JAXB2简化插件,因为JAXB会阻止您执行想要的(反序列化)操作从XML到Java前后均保持一致(即,您需要保留顺序)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM