Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set to default to json instead of xml in jersey?

Tags:

java

jersey

Using jersey jersey.java.net How do I set JSON as the default serialization instead of XML when there is no accept header or .xml suffix is in the URI?

like image 848
Rolando Avatar asked Oct 04 '11 14:10

Rolando


2 Answers

You can assign the quality index to each media type in @Produces annotation. I.e.you can do the following to make Jersey prefer JSON if both XML and JSON are allowed:

@Produces({"application/json;qs=1", "application/xml;qs=.5"})
like image 167
Martin Matula Avatar answered Oct 27 '22 23:10

Martin Matula


You should be able to set the @Produces annotation to specify the return format like so:

@Produces( { "application/json" })

How come there is no accepts header?

like image 43
Gerard Avatar answered Oct 27 '22 23:10

Gerard