2013-04-15 30 views
0

我有這個類設置爲空字符串作爲XSI:無=真

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" /> 

我該怎麼做?

+0

如果您希望所有元素都可用,您可以從WSDL/XSD生成JAXB對象,那麼您可以告訴生成器爲您添加'XmlElement(nillable = true)'。 –

+0

告訴發電機是什麼意思?我怎麼做? – Nacho321

回答

1

使用以下編組

@XmlElement(nillable = true) 
protected String userMessage; 

如果WSDL/XSD具有元件defind作爲的nillable當將治療null作爲一個零,則代碼生成將生成下列

protected JaxbElement<String> userMessage; 

我可以從你的javadoc知道,生成的代碼不是你今天使用的。如果你擊中他人的web服務,我建議從他們的wsdl生成正確的dto對象。您可以查看在jdk/bin目錄中找到的xjc.exe和wsdl.exe的文檔。