2012-10-03 34 views
1

我試圖用我的對象與JAXB註釋與我的JAX-RS資源應用/ JSON輸出。我在JBoss AS7與RestEasy的( - 7.1.1.Final和2.3.4.Final兩個最新的版本)運行。問題是我想定製我的JSON輸出。我必須指出,我不介意,我將使用拋棄或傑克遜,但我可以做只是拋棄工作(部署應用程序)沒有錯誤。如果可能的話,我也只想在我的對象上粘貼JAXB註釋 - 但這不是必需的。RestEasy的拋棄/傑克遜定製

1)我想省略 「@」 XmlAttribute註釋字段中。我發現財產如何與Jettison做到這一點,但我不知道如何在JBoss AS7上進行配置。沒有找到任何ContextResolver示例。

2)I想有 「正常」 的JSON陣列,例如

@XmlRootElement(name = "root") 
@XmlAccessorType(XmlAccessType.FIELD) 
public class Root { 

    @XmlElementRef(type = Entry.class, required = false) 
    // no difference with @XmlElement 
    private Set<Entry> entries; 
} 

序列化到

{"entries": 
    {"entry":[{...},{...},{...}]} 
} 

,我會想到

{"entries": 
    [ 
    {"entry":{...}}, 
    {"entry":{...}}, 
    {"entry":{...}}  
    ] 
} 

或只是(省略XmlRootElement將)

{"entries": 
[{...},{...},{...}] 
} 

3)正如我指出的,我不知道關心什麼提供者(Jettison /傑克遜)我會不會e但很難找到工作示例如何正確設置應用程序的Maven依賴關係,以便無錯地部署。到目前爲止,我使用:

<dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jaxrs</artifactId> 
     <version>${resteasyVersion}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jaxb-provider</artifactId> 
     <version>${resteasyVersion}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jettison-provider</artifactId> 
     <version>${resteasyVersion}</version> 
     <!--<scope>provided</scope>--> 
     <exclusions> 
      <exclusion> 
       <groupId>javax.xml.bind</groupId> 
       <artifactId>jaxb-api</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>com.sun.xml.bind</groupId> 
       <artifactId>jaxb-impl</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>javax.xml.stream</groupId> 
       <artifactId>stax-api</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

感謝所有答案

+0

人說使用傑克遜,但1:目前還不清楚哪一個的Jboss 7.1默認情況下使用2:只是增加了對傑克遜的依賴給了我的錯誤,讓我永遠不能得到更容易編寫ContextResolver的部分。看起來很難配置Jettison並通過Google搜索進行判斷,Jettison不太受歡迎,而且肯定沒有文檔和教程。 – user798719

回答

0

到目前爲止,我設法讓傑克遜工作,並利用其特定供應商的註解(@JsonProperty ...等),它解決了我的問題。我試圖找到只有JAXB解決方案,但我也可以接受這一點。

順便說一下我的依賴

<dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jaxrs</artifactId> 
     <version>${resteasyVersion}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jaxb-provider</artifactId> 
     <version>${resteasyVersion}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jackson-provider</artifactId> 
     <version>${resteasyVersion}</version> 
    </dependency>