Java/JAXB : Adding id to my element without making this appear in the XML file
up vote
0
down vote
favorite
I want to add an id
to my element, but I don't want this to appear in my XML file. So I tried not to put @XmlAttribute
nor @XmlElement
, but it always appears. I just want to set my id
for my object, to get it back for something else in my program.
Here is my Java code in JAXB (simplified) :
public class Equipment {
private String label;
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@XmlAttribute
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}
And here it is the result when I create my XML file :
<site label="test">
<equipment id="2" label="test">
</equipment>
</site>
As you can see id
appears, but it shouldn't.
Thanx !
java xml jaxb attributes
add a comment |
up vote
0
down vote
favorite
I want to add an id
to my element, but I don't want this to appear in my XML file. So I tried not to put @XmlAttribute
nor @XmlElement
, but it always appears. I just want to set my id
for my object, to get it back for something else in my program.
Here is my Java code in JAXB (simplified) :
public class Equipment {
private String label;
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@XmlAttribute
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}
And here it is the result when I create my XML file :
<site label="test">
<equipment id="2" label="test">
</equipment>
</site>
As you can see id
appears, but it shouldn't.
Thanx !
java xml jaxb attributes
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to add an id
to my element, but I don't want this to appear in my XML file. So I tried not to put @XmlAttribute
nor @XmlElement
, but it always appears. I just want to set my id
for my object, to get it back for something else in my program.
Here is my Java code in JAXB (simplified) :
public class Equipment {
private String label;
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@XmlAttribute
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}
And here it is the result when I create my XML file :
<site label="test">
<equipment id="2" label="test">
</equipment>
</site>
As you can see id
appears, but it shouldn't.
Thanx !
java xml jaxb attributes
I want to add an id
to my element, but I don't want this to appear in my XML file. So I tried not to put @XmlAttribute
nor @XmlElement
, but it always appears. I just want to set my id
for my object, to get it back for something else in my program.
Here is my Java code in JAXB (simplified) :
public class Equipment {
private String label;
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@XmlAttribute
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}
And here it is the result when I create my XML file :
<site label="test">
<equipment id="2" label="test">
</equipment>
</site>
As you can see id
appears, but it shouldn't.
Thanx !
java xml jaxb attributes
java xml jaxb attributes
edited 14 hours ago
Thomas Fritsch
4,530121832
4,530121832
asked 17 hours ago
Laliana
32
32
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
In your Equipment
class you need to tell JAXB that it should ignore the
id
property. You do this by annotating it with @XmlTransient
(instead of with
@XmlAttribute
or @XmlElement
).
@XmlTransient
public Integer getId() {
return id;
}
This should result in XML output like this:
<site label="test">
<equipment label="test"/>
</site>
Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
– Laliana
13 hours ago
@Laliana Glad to hear this :) You should accept the answer if it solved your problem.
– Thomas Fritsch
13 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
In your Equipment
class you need to tell JAXB that it should ignore the
id
property. You do this by annotating it with @XmlTransient
(instead of with
@XmlAttribute
or @XmlElement
).
@XmlTransient
public Integer getId() {
return id;
}
This should result in XML output like this:
<site label="test">
<equipment label="test"/>
</site>
Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
– Laliana
13 hours ago
@Laliana Glad to hear this :) You should accept the answer if it solved your problem.
– Thomas Fritsch
13 hours ago
add a comment |
up vote
0
down vote
accepted
In your Equipment
class you need to tell JAXB that it should ignore the
id
property. You do this by annotating it with @XmlTransient
(instead of with
@XmlAttribute
or @XmlElement
).
@XmlTransient
public Integer getId() {
return id;
}
This should result in XML output like this:
<site label="test">
<equipment label="test"/>
</site>
Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
– Laliana
13 hours ago
@Laliana Glad to hear this :) You should accept the answer if it solved your problem.
– Thomas Fritsch
13 hours ago
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
In your Equipment
class you need to tell JAXB that it should ignore the
id
property. You do this by annotating it with @XmlTransient
(instead of with
@XmlAttribute
or @XmlElement
).
@XmlTransient
public Integer getId() {
return id;
}
This should result in XML output like this:
<site label="test">
<equipment label="test"/>
</site>
In your Equipment
class you need to tell JAXB that it should ignore the
id
property. You do this by annotating it with @XmlTransient
(instead of with
@XmlAttribute
or @XmlElement
).
@XmlTransient
public Integer getId() {
return id;
}
This should result in XML output like this:
<site label="test">
<equipment label="test"/>
</site>
edited 14 hours ago
answered 14 hours ago
Thomas Fritsch
4,530121832
4,530121832
Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
– Laliana
13 hours ago
@Laliana Glad to hear this :) You should accept the answer if it solved your problem.
– Thomas Fritsch
13 hours ago
add a comment |
Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
– Laliana
13 hours ago
@Laliana Glad to hear this :) You should accept the answer if it solved your problem.
– Thomas Fritsch
13 hours ago
Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
– Laliana
13 hours ago
Thanx a lot ! It totally works :D I was looking for Jaxb annotations but I didn't completely understand the meaning (I'm french). But now, that you're explaining, I understand. Thanx :)
– Laliana
13 hours ago
@Laliana Glad to hear this :) You should accept the answer if it solved your problem.
– Thomas Fritsch
13 hours ago
@Laliana Glad to hear this :) You should accept the answer if it solved your problem.
– Thomas Fritsch
13 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371852%2fjava-jaxb-adding-id-to-my-element-without-making-this-appear-in-the-xml-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown