java


How to represent a response body in xml


Hello i'm using spring framework and the default representation is in JSON. I am attempting to represent the response body in 3 formats. Xml, json and html. Default way is json but having trouble in representing in xml and html. how would you want the response body to be in xml and html. I get a 406 error when running the code.
in my pom xml: i declared
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.6.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.6.3</version>
</dependency>
and in my dispatcher-servlet.xml:
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" >
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
</list>
</property>
</bean>
And finally my controller method:
#RequestMapping(value="person/{id}", method=RequestMethod.GET, params="format=xml", produces=MediaType.APPLICATION_XML_VALUE)
#ResponseBody
public ResponseEntity<?> PersoninXML(#PathVariable("id")Long id) {
Person person = personDAO.findById(id);
if(person!=null){
return new ResponseEntity<Person>(person, HttpStatus.OK);
}
else
return new ResponseEntity<String>("Id doesn't exist", HttpStatus.NOT_FOUND);
}

Related Links

Anonymous class objects: which variables do they see?
How to retrieve read-only attributes from ldap using Spring
Posting to Blogger using java
Using String Buffer For String Appends in Java [duplicate]
Sharing src/test classes with Maven without version specification for test-jar
Mongo/Morphia too many connections Exception
Templates in Eclipse
HTML hyperlink are not available in Jasper report
Gradle: Comparing maven and gradle artifacts built from the same source
How to get result from multiple query on multiple collection of mongo in eventBus vertx2?
Where maven places library files
Exception starting filter xss while deploying webapp in tomcat
Login an Logout misundertanding
Log in system .txt file reading issues
Store the attribute's value of a WebElement in Selenium Webdriver
Parsing ISO 8583:1993 with j8583

Categories

HOME
zeromq
azure-data-factory
pycharm
plone
angular-material
platform-builder
grep
kalman-filter
binary-tree
virtualization
primary-key
windows-phone-7
msp430
decimal
jsprit
quartz-scheduler
iolanguage
systemc
openedx
firefox-webextensions
scichart
dbext
predix
graphicsmagick
csrf-protection
telerik-reporting
shopware
tdd
kannel
xacml
windows-server-2000
newline
srcset
frame
data-manipulation
pim
file-format
dartium
adobe-premiere
swisscomdev
web-mining
code-search-engine
sqlite2
unobtrusive-validation
ansible-playbook
streamreader
optix
ncalc
elmah
node-gyp
heightmap
angular2-meteor
wptoolkit
galleria
avconv
parentheses
azure-application-gateway
nstextview
drupal-6
google-perftools
windows-iot-core-10
ifs
zendesk-app
flow-control
synchronous
instant
android-textview
home-directory
intrusion-detection
fody
impresspages
actionbardrawertoggle
rvest
yaws
maven-tomcat-plugin
t4mvc
python-3.2
map-projections
ionic
ibaction
responsive-images
arcanist
oberon
dereference
streambase
inmobi
c++03
bigbluebutton
typekit
xc16
dd
terminfo
castle
system.net.webexception
xceed-datagrid
seaside
hyprlinkr
srs
html5-notifications
django-nonrel
flashvars
kyotocabinet
hamiltonian-cycle
jquery-knob
mt
venn-diagram
ticoredatasync
netbeans-6.9
removeclass
adk
gcj
mod-auth
yslow
infrastructure
revisions
fixed-width
multi-tier
brewmp
libs
sector
post-build
commodore
ajax-forms

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App