开发者

JAXB don't generate attribute from java class

开发者 https://www.devze.com 2023-04-09 17:26 出处:网络
I have a class like the following: @XmlRootElement(name = \"task\") class Task{ @XmlElement(name = \"id\")

I have a class like the following:

@XmlRootElement(name = "task")
class Task{
  @XmlElement(name = "id")
  Integer id;
  @XmlElement(name = "name")
  String name;
  String bzId;
}

I want to generate an xml like 开发者_JS百科the following:

<task>
  <id>1</id>
  <name>String</name>
</task>

I can't seem to find it anywhere. How can i not generate the "bzId" in my example?


you need to use the @XmlTransient annotation. Same this as the transient keyword, but for xml :D.

You can also use the @XmlAccessorType on the class to change the default behaviour and just serialize annotated attributes.

0

精彩评论

暂无评论...
验证码 换一张
取 消