2016-04-12 38 views
3

我想創建一個人休息service.And我試圖創建XML模式使用JAXB和JSon架構使用傑克遜。如何從xml中刪除元素名稱?

所以這裏是我的模型類來創建各自的XML以及JSon有效載荷。

package www.tempuri.person.model; 

import io.swagger.annotations.ApiModel; 
import io.swagger.annotations.ApiModelProperty; 
import javax.xml.bind.annotation.XmlRootElement; 
import com.fasterxml.jackson.annotation.JsonRootName; 

@ApiModel(value="GetPerson Message",description = "Personal Input Request") 
@XmlRootElement(name="getPerson") 
@JsonRootName(value = "getPerson") 
public class GetPersonWrapper { 

    @ApiModelProperty(value = "GetPerson", required = true) 
    private GetPerson getPerson; 

    public GetPerson getGetPerson() { 
     return getPerson; 
    } 

    public void setGetPerson(GetPerson getPerson) { 
     this.getPerson = getPerson; 
    } 
} 

package www.tempuri.person.model; 

import io.swagger.annotations.ApiModel; 
import io.swagger.annotations.ApiModelProperty; 

@ApiModel(description = "Represents Persons") 
public class GetPerson { 

    @ApiModelProperty(value = "Application Area of GetPerson", required = true) 
    private ApplicationArea applicationArea; 

    @ApiModelProperty(value = "Data Area of GetPerson", required = true) 
    private DataAreaGet dataArea; 

    /** 
    * @return the dataArea 
    */ 
    public DataAreaGet getDataArea() { 
     return dataArea; 
    } 

    /** 
    * @param dataArea the dataArea to set 
    */ 
    public void setDataArea(DataAreaGet dataArea) { 
     this.dataArea = dataArea; 
    } 

    public ApplicationArea getApplicationArea() { 
     return applicationArea; 
    } 

    public void setApplicationArea(ApplicationArea applicationArea) { 
     this.applicationArea = applicationArea; 
    } 
} 

通過上述模型類,json模式即將到來。但在XML中的情況下,我不能夠得到什麼,我想: 下面是它在XML生成的架構:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<getPerson> 
    <getPerson> 
     <applicationArea/> 
     <dataArea> 
      <description>string</description> 
      <id>0</id> 
      <name>string</name> 
     </dataArea> 
    </getPerson> 
</getPerson> 

正如你可以看到我的獲得兩個getPerson節點。我如何才能使用jaxb註釋去除其中一個getPerson節點。

我使用apache camel swagger組件來創建其餘服務。

期待您的解決方案。提前致謝。

回答

0

我會使用XSLT,簡單直接,簡單,像魔術一樣工作。