
|
If you were logged in you would be able to see more operations.
|
|
|
XStream
Created: 17/Jul/07 02:58 PM
Updated: 25/Feb/08 05:01 PM
|
|
| Component/s: |
Annotations
|
| Affects Version/s: |
None
|
| Fix Version/s: |
1.3
|
|
| JDK version and platform: |
all
|
|
@XStreamAsAttribute currently works dont works with enum types, its necessary a specialized converter, the annotation needs the same behavior for enums and object attributes.
Example,
public class Field {
@XStreamAsAttribute
String name;
@XStreamAsAttribute
int bits;
@XStreamAsAttribute
Type type;
// set ang get
}
public enum Type {
TEXT ,
NUMBER;
}
public class TestEnumAttribute {
public static void main(String[] args) {
XStream xstream = new XStream(new DomDriver());
Field field = new Field();
field.setName("serial");
field.setBits(224);
field.setType(Type.TEXT);
Annotations.configureAliases(xstream, Field.class);
String xml = xstream.toXML(field);
System.out.println(xml);
}
}
Current result:
<fieldname="serial" bits="224">
<type>TEXT</type>
<field>
The new return:
<field name="serial" bits="224" type="TEXT" />
|
|
Description
|
@XStreamAsAttribute currently works dont works with enum types, its necessary a specialized converter, the annotation needs the same behavior for enums and object attributes.
Example,
public class Field {
@XStreamAsAttribute
String name;
@XStreamAsAttribute
int bits;
@XStreamAsAttribute
Type type;
// set ang get
}
public enum Type {
TEXT ,
NUMBER;
}
public class TestEnumAttribute {
public static void main(String[] args) {
XStream xstream = new XStream(new DomDriver());
Field field = new Field();
field.setName("serial");
field.setBits(224);
field.setType(Type.TEXT);
Annotations.configureAliases(xstream, Field.class);
String xml = xstream.toXML(field);
System.out.println(xml);
}
}
Current result:
<fieldname="serial" bits="224">
<type>TEXT</type>
<field>
The new return:
<field name="serial" bits="224" type="TEXT" />
|
Show » |
|