0

我有这门课

package com.ni.schemas.provider_framework._1.providers;

import java.math.BigInteger;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
 * 
 *                 This is the top-level for a Request. 
 *                 Providers may extend this type if needed, but may not restrict it by blocking the pre-defined elements
 *             
 * 
 * <p>Clase Java para RequestErrorType complex type.
 * 
 * <p>El siguiente fragmento de esquema especifica el contenido que se espera que haya en esta clase.
 * 
 * <pre>
 * &lt;complexType name="RequestErrorType">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="httpResponseCode" type="{http://www.w3.org/2001/XMLSchema}integer"/>
 *         &lt;group ref="{http://www.ni.com/schemas/provider-framework/1/providers}ErrorElementGroup"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "RequestErrorType", propOrder = {
    "httpResponseCode",
    "summary",
    "userMessage",
    "detail"
})
public class RequestErrorType {

    @XmlElement(required = true)
    protected BigInteger httpResponseCode;
    protected String summary;
    protected String userMessage;
    protected String detail;

    /**
     * Obtiene el valor de la propiedad httpResponseCode.
     * 
     * @return
     *     possible object is
     *     {@link BigInteger }
     *     
     */
    public BigInteger getHttpResponseCode() {
        return httpResponseCode;
    }

    /**
     * Define el valor de la propiedad httpResponseCode.
     * 
     * @param value
     *     allowed object is
     *     {@link BigInteger }
     *     
     */
    public void setHttpResponseCode(BigInteger value) {
        this.httpResponseCode = value;
    }

    /**
     * Obtiene el valor de la propiedad summary.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getSummary() {
        return summary;
    }

    /**
     * Define el valor de la propiedad summary.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setSummary(String value) {
        this.summary = value;
    }

    /**
     * Obtiene el valor de la propiedad userMessage.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getUserMessage() {
        return userMessage;
    }

    /**
     * Define el valor de la propiedad userMessage.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setUserMessage(String value) {
        this.userMessage = value;
    }

    /**
     * Obtiene el valor de la propiedad detail.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getDetail() {
        return detail;
    }

    /**
     * Define el valor de la propiedad detail.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setDetail(String value) {
        this.detail = value;
    }

}

如果我想将 userMessage 变量设置为 null,在显示时,只是显示这个

<userMessage />

我需要显示

<userMessage xsi:nil="true" />

我怎样才能做到这一点?

4

1 回答 1

1

编组时使用以下内容将 null 视为 nil

@XmlElement(nillable = true)
protected String userMessage;

如果 WSDL/XSD 将元素定义为 nillable,则代码生成将生成以下内容

protected JaxbElement<String> userMessage;

我可以从您的 javadoc 中看出,生成的代码不是您今天使用的。如果您遇到其他人的网络服务,我建议从他们的 wsdl 生成正确的 dto 对象。您可以查看在 jdk/bin 目录中找到的 xjc.exe 和 wsdl.exe 的文档。

于 2013-04-15T18:23:49.627 回答