Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
eganba
eganba's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
JAXB bind single XML element to Java object
[0 Replies]
19-Feb-2013 04:56 AM
Forum:
Programming Questions
Hi,
I am having troubles binding a single element into an object with several attributes.
Here's what I have:
My XML (cannot be modified):
<type>
<name>some name</name>
<subtype1>aaaaaa</subtype1>
<subtype2>bbbbbb</subtype2>
</type>
My Java classes
@XmlRootElement(name = "type")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class Type {
protected String name;
protected List<SubType> list;
// getters
@XmlElement(name = "name")
public String getName() {
return name;
}
@XmlElements({
@XmlElement(name = "subtype1", type = SubType.class),
@XmlElement(name = "subtype1", type = SubType.class)
})
public List<SubType> getList() {
return list;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public class SubType {
protected String defaultValue = "DEFAULT";
protected String subtype= null;
// getters
.....
}
I parse XML with Type class and get a correct value for name attribute.
However I cannot bind subtype1 and subtype2 nodes into SubType classes (subtype attribute is always empty).
Can someone please tell me if it's possible to bind an element to a class/object?
To modify classes to make it work ?
Thank you.
«Prev
Next »
Moderate user : eganba
Forum