albacoreylerf
New Member
I was trying to follow http://eggsylife.co.uk/2010/01/03/spring-3-restful-web-services/\[/quote\]and the server returns an xml version of the object classroom:\[code\]@XmlRootElement(name = "class") public class Classroom { private String classId = null; private ArrayList<Student> students = null; public Classroom() { } public String getClassId() { return classId; } public void setClassId(String classId) { this.classId = classId; } @XmlElement(name="student") public ArrayList<Student> getStudents() { return students; } public void setStudents(ArrayList<Student> students) { this.students = students; } }\[/code\]The object Student is another bean containing only Strings. In my app-servlet.xml i copied this lines:\[code\]<bean id="studentsView" class="org.springframework.web.servlet.view.xml.MarshallingView"> <constructor-arg ref="jaxbMarshaller" /></bean><!-- JAXB2 marshaller. Automagically turns beans into xml --><bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <property name="classesToBeBound"> <list> <value>com.spring.datasource.Classroom</value> <value>com.spring.datasource.Student</value> </list> </property></bean>\[/code\]Now my question is: what if i wanted to insert some non-string objects as class variables? Let's say i want a tag containing the String version of an InetAddress, such as\[code\]<inetAddress>192.168.1.1</inetAddress>\[/code\]How can i force JAXB to call the method inetAddress.toString() in such a way that it appears as a String in the xml? In the returned xml non-string objects are ignored!