2012-09-08 50 views
1

我JAXB對象模型的實例包含我想輸出時,我產生了例如XML,但不是當我產生JSON我可以讓MOXY在生成json時不輸出元素嗎?

即我想

<release-group> 
<type>Album</type> 
<title>Fred</title> 
</release-group> 

"release-group" : { 
     "title" : "fred", 
     }, 
元素

但有

"release-group" : { 
     "type" : "Album", 
     "title" : "fred" 
     },   

我可以這樣做嗎?使用oxml.xml映射文件

這個答案顯示了我可以如何使用transient關鍵字Can I get MOXy to not output an attribute when generating json?來實現屬性,但是我無法讓它在元素中工作。

回答

1

對不起問題解決了,對我來說有點混亂。

我上面給沒有實際的真實情況準確地匹配例如,鍵入實際上是作爲對XML屬性輸出,但在使用的瞬間沒有工作,因爲它一直在JAXB

@XmlAttribute(name = "target-type", required = true) 
@XmlSchemaType(name = "anyURI") 
protected String targetType; 

改名所以加入

<java-type name="ReleaseGroup"> 
      <java-attributes> 
       <xml-transient java-attribute="targetType"/> 
      </java-attributes> 
     </java-type> 

工作,以前我是做不正確

<java-type name="ReleaseGroup"> 
      <java-attributes> 
       <xml-transient java-attribute="target-type"/> 
      </java-attributes> 
     </java-type> 
相關問題