bboyle18
10 Aug 2010, 12:39 PM
Hi,
I'm trying to convert a simple GXT BaseModel object to XML using XStream.
I am having problems though as my XML is not coming out as I expect. I think this is because BaseModel uses an RcpMap to store the data, rather than assigning the values to member variables as you would expect for a regular POJO.
I have seen a few comments on the forums already of people saying that they are using XStream with GXT, but no examples of how its done.
I'd be grateful if anyone who has used it can let me know and perhaps point me in the right direction for this.
Cheers,
Brian
P.S. below is my code
*/
public class CarModel extends BaseModel {
private String name;
private String colour;
private int numberPlate;
private int age;
public CarModel(String name, String colour, int numberPlate, int age) {
set("name", name);
set("colour", colour);
set("numberPlate", numberPlate);
set("age", age);
}
/**
* @return the name
*/
public String getName() {
return get("name");
}
/**
* @param name the name to set
*/
public void setName(String name) {
set("name", name);
}
/**
* @return the colour
*/
public String getColour() {
return get("colour");
}
/**
* @param colour the colour to set
*/
public void setColour(String colour) {
set("colour", colour);
}
/**
* @return the numberPlate
*/
public int getNumberPlate() {
return get("numberPlate");
}
/**
* @param numberPlate the numberPlate to set
*/
public void setNumberPlate(int numberPlate) {
set("numberPlate", numberPlate);
}
/**
* @return the age
*/
public int getAge() {
return get("age");
}
/**
* @param age the age to set
*/
public void setAge(int age) {
set("age", age);
}
This is my converter class
public class GXTToXMLConverter {
public String convertToXML(CarModel carModel) {
XStream xStream = new XStream();
xStream.alias("car", CarModel.class);
String xml = xStream.toXML(carModel);
System.out.println(xml);
return xml;
}
}
And finally, here is my test
public void testConvertToXML() throws Exception{
CarModel car = new CarModel("Audi", "Silver", 9023423, 9);
String xml = converter.convertToXML(car);
assertNotNull(xml);
}
Result is this
<car>
<map/>
<allowNestedValues>true</allowNestedValues>
<numberPlate>0</numberPlate>
<age>0</age>
</car>
I'm trying to convert a simple GXT BaseModel object to XML using XStream.
I am having problems though as my XML is not coming out as I expect. I think this is because BaseModel uses an RcpMap to store the data, rather than assigning the values to member variables as you would expect for a regular POJO.
I have seen a few comments on the forums already of people saying that they are using XStream with GXT, but no examples of how its done.
I'd be grateful if anyone who has used it can let me know and perhaps point me in the right direction for this.
Cheers,
Brian
P.S. below is my code
*/
public class CarModel extends BaseModel {
private String name;
private String colour;
private int numberPlate;
private int age;
public CarModel(String name, String colour, int numberPlate, int age) {
set("name", name);
set("colour", colour);
set("numberPlate", numberPlate);
set("age", age);
}
/**
* @return the name
*/
public String getName() {
return get("name");
}
/**
* @param name the name to set
*/
public void setName(String name) {
set("name", name);
}
/**
* @return the colour
*/
public String getColour() {
return get("colour");
}
/**
* @param colour the colour to set
*/
public void setColour(String colour) {
set("colour", colour);
}
/**
* @return the numberPlate
*/
public int getNumberPlate() {
return get("numberPlate");
}
/**
* @param numberPlate the numberPlate to set
*/
public void setNumberPlate(int numberPlate) {
set("numberPlate", numberPlate);
}
/**
* @return the age
*/
public int getAge() {
return get("age");
}
/**
* @param age the age to set
*/
public void setAge(int age) {
set("age", age);
}
This is my converter class
public class GXTToXMLConverter {
public String convertToXML(CarModel carModel) {
XStream xStream = new XStream();
xStream.alias("car", CarModel.class);
String xml = xStream.toXML(carModel);
System.out.println(xml);
return xml;
}
}
And finally, here is my test
public void testConvertToXML() throws Exception{
CarModel car = new CarModel("Audi", "Silver", 9023423, 9);
String xml = converter.convertToXML(car);
assertNotNull(xml);
}
Result is this
<car>
<map/>
<allowNestedValues>true</allowNestedValues>
<numberPlate>0</numberPlate>
<age>0</age>
</car>