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

What does (savedInstanceState) mean
While and try-catch stracture and exceptions
exponentially increasing startup time (Spring initialization) on every added DAO interface
Jacob: Call to VBA failed
No message body writer has been found for response class when accessing the service
How can I Refactor enum class valueof method?
Maven PMD plug-in not generating a report with 'mvn site' command or 'pmd:pmd'
How can I improve my android studio installation? [closed]
how do you write out if an element is a member of an array in a boolean statement that is also recursive?
JMM and multithreaded communication with external devices and atomic variables
HTTP 204 error in REST (Dropwizard)
What use does the == operator have for String?
solr indexing - connection timeout
Java - Converting to BigInteger
How to use Crashlytics with RoboVM iOS binding?
Prompt the user to enter three integers, find the largest of these 3 integers and find square of that largest number

Categories

HOME
hive
oracle11g
heroku
hp-exstream
jsp-tags
yarn
amortized-analysis
paradox
kentor-authservices
offline
wheelnav.js
mapserver
google-apps-marketplace
circuit
django-admin
footer
reactcsstransitiongroup
excel-vba-mac
shared-hosting
ml
clickonce
zurb-foundation-6
claims-based-identity
dxf
angular2-aot
semantic-analysis
uninstall
windows-error-reporting
wtx
stormpath
preg-match-all
uisplitview
create-table
textmate
uiswipegesturerecognizer
code-search-engine
sharefile
splice
particles.js
reportingservices-2005
unixodbc
scorm
ionicons
recursive-datastructures
linode
mcafee
instant
bluegiga
associative-array
browser-link
maven-tomcat-plugin
teamcity-8.0
atk4
ideamart
device-orientation
apache-commons-net
nstableviewcell
nsbutton
aapt
android-2.2-froyo
didselectrowatindexpath
intentservice
prettify
inbox
django-nonrel
comaddin
interface-orientation
pvrtc
libstdc++
cascalog
newtonscript
reddot
eclipse-templates
ecl
mongomapper
lpeg
zend-translate
gamma
firefox-5
webkit.net
nintendo-ds
javap
private-members
data-acquisition
wsdl.exe
.net-1.0
paul-graham
rtml

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App