我可以让MOXy在生成json时不输出元素吗?
JAXB对象模型的一个实例包含一个元素,我希望在为该实例生成Xml时输出该元素,但在生成json时不输出该元素 i、 我想要我可以让MOXy在生成json时不输出元素吗?,json,eclipselink,moxy,Json,Eclipselink,Moxy,JAXB对象模型的一个实例包含一个元素,我希望在为该实例生成Xml时输出该元素,但在生成json时不输出该元素 i、 我想要 <release-group> <type>Album</type> <title>Fred</title> </release-group> 但是有 "release-group" : { "type" : "Album", "title" : "fred"
<release-group>
<type>Album</type>
<title>Fred</title>
</release-group>
但是有
"release-group" : {
"type" : "Album",
"title" : "fred"
},
我可以使用oxml.xml映射文件执行此操作吗
这个答案说明了如何使用transient关键字处理属性,但我无法将其用于元素。抱歉,问题解决了,我有点困惑 我上面给出的示例实际上并不准确地匹配真实情况,类型实际上是作为Xml的属性输出的,但是使用transient不起作用,因为它已在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>
对不起,问题解决了,我有点困惑 我上面给出的示例实际上并不准确地匹配真实情况,类型实际上是作为Xml的属性输出的,但是使用transient不起作用,因为它已在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>