Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jaxb:内联元素_Java_Xml_Jaxb - Fatal编程技术网

Java jaxb:内联元素

Java jaxb:内联元素,java,xml,jaxb,Java,Xml,Jaxb,鉴于: 如何进行注释,使XML为: @XmlRootElement(name = "foo") class Foo { public Bar getBar() {...} } class Bar { @XmlElement(name = "string") public String getString() {return "hello";} } 你好 您可能需要在类的顶部使用注释 当您希望在XML输出中包含另一个实体bean时,可以使用@xmlseealannotati

鉴于:

如何进行注释,使XML为:

@XmlRootElement(name = "foo")
class Foo {
   public Bar getBar() {...}
}

class Bar {
   @XmlElement(name = "string")
   public String getString() {return "hello";}
}

你好
您可能需要在类的顶部使用注释

当您希望在XML输出中包含另一个实体bean时,可以使用@xmlseealannotation。你能在你的Foo课上试试这个吗

<foo>
   <string>hello</string>
</foo>
更新1:

对于要删除XML中的bar标记的注释,请尝试使用@XmlPath将解决您的问题

@XmlRootElement(name = "foo")
@XmlSeeAlso(Bar.class)
class Foo {
   public Bar getBar() {...}
}
有关更多详细信息,请参阅。

您可能需要在类的顶部使用注释

当您希望在XML输出中包含另一个实体bean时,可以使用@xmlseealannotation。你能在你的Foo课上试试这个吗

<foo>
   <string>hello</string>
</foo>
更新1:

对于要删除XML中的bar标记的注释,请尝试使用@XmlPath将解决您的问题

@XmlRootElement(name = "foo")
@XmlSeeAlso(Bar.class)
class Foo {
   public Bar getBar() {...}
}

有关更多详细信息,请参阅。

我不确定您是否可以从生成的XML中删除标记条:


我不确定您是否可以从生成的XML中删除标记条:


您可以利用
@XmlValue
注释执行以下操作

Foo

@XmlRootElement(name = "foo")
@XmlSeeAlso(Bar.class)
class Foo {
   @XmlPath(".")
   public Bar getBar() {...}
}

@XmlRootElement
class Foo {
    @XmlElement(name="string")
    public Bar getBar() {...}
}
了解更多信息


您可以利用
@XmlValue
注释执行以下操作

Foo

@XmlRootElement(name = "foo")
@XmlSeeAlso(Bar.class)
class Foo {
   @XmlPath(".")
   public Bar getBar() {...}
}

@XmlRootElement
class Foo {
    @XmlElement(name="string")
    public Bar getBar() {...}
}
了解更多信息


这是否仍然会导致hello?+1-您可以使用MOXy的
@XmlPath
扩展来实现此用例,但请查看我的答案,了解如何仅使用标准JAXB注释来实现此目的:。此用例不需要
@xmlseea
注释。这是否仍然会导致hello?+1-您可以在此用例中使用MOXy的
@XmlPath
扩展,但请查看我的答案,了解如何仅使用标准JAXB注释来完成此操作:。这个用例不需要
@xmlseea
注释。按照问题的表述方式,这个答案在技术上是正确的,应该被接受,尽管我猜这不是OP想要的。我想OP的主要关注点是消除。。。标记,而不是字符串的呈现,而是XML内容。他可能想(和我一样)一个“Bar”对象,它除了一个字符串之外还包含很多东西,他希望所有这些东西都显示为“Foo”的直接子对象,而不带“Bar”标签。按照问题的表述方式,这个答案在技术上是正确的,应该被接受,尽管我猜这不是OP想要的。我想OP的主要关注点是消除。。。标记,而不是字符串的呈现,而是XML内容。他可能想(和我一样)一个“Bar”对象,它除了一个字符串之外还包含很多东西,他希望所有这些东西都显示为“Foo”的直接子对象,而不带“Bar”标记。