java - Stop converting < to <, > to > and & to & in spring controller response -
i trying generate small xml. xml should have cdata in it. problem managed generate cdata, xml generated have < , > , &
i using spring-mvc. interested in getting right xml cdata in it.
sample xml follow :
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <customer> <active>1</active> <alertmessage></alertmessage> <currency>gbp</currency> <customernumber>123</customernumber> <forename>ad</forename> <balancetoallow> <balance saving="10" spend="9990" type="2"> <value>\<![cdata[$100 off on 2 purchase of jeans xyz brand.]]\></value> </balance> </balancetoallow> <surname>cd</surname> </customer>
i have overridden 1 of converter follow.
<mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.xml.jaxb2rootelementhttpmessageconverter"> </bean> </mvc:message-converters> </mvc:annotation-driven>
p.s using spring rest controller web service.
here model class :
public class balance{ private string value; private string type; private string saving; private string spend; public string getvalue() { return value; } @xmljavatypeadapter(adaptercdata.class) public void setvalue(string value) { this.value = value; } public string gettype() { return type; } @xmlattribute public void settype(string type) { this.type = type; } public string getsaving() { return saving; } @xmlattribute public void setsaving(string saving) { this.saving = saving; } public string getspend() { return spend; } @xmlattribute public void setspend(string spend) { this.spend = spend; } }
this class again part of class.
public class balancetoallows { private list<balance> balancetoallow ; public list<balance> getbalancetoallow () { return balancetoallow; } @xmlelement(name="balancetoallow ") public void setbalancetoallow (list<balance > balancetoallow ) { this.balancetoallow= balancetoallow; } }
and part of class. parent class.
@xmlrootelement(name = "customer") public class customer { private string surname ; private string forename; private balancetoallow balancetoallow; private final string active="1"; private final string currency = "gbp"; private final string alertmessage=""; public string getcustomernumber() { return customernumber; } @xmlelement(name="customernumber") public void setcustomernumber(string customernumber) { this.customernumber = customernumber; } @xmlelement(name="active") public string getactive() { return active; } @xmlelement(name="currency") public string getcurrency() { return currency; } public string getsurname() { return surname; } @xmlelement(name="surname") public void setsurname(string surname) { this.surname = surname; } public string getforename() { return forename; } @xmlelement(name="forename") public void setforename(string forename) { this.forename = forename; } @xmlelement(name="alertmessage") public string getalertmessage() { return alertmessage; } public balancetoallow getbalancetoallow() { return balancetoallow; } @xmlelement(name="balancetoallow") public void setfuturepromotions(balancetoallow balancetoallow) { this.balancetoallow= balancetoallow; } }
thanks reading.
Comments
Post a Comment