0

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 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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks Augusto, this is just what i needed i will use the @XmlAccessorType after all because i will wrap the task in a <tasks> tag so no need for the XmlRootElement...the link in your answer is great, thanks for that as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.