如何在球衣中将默认设置为 json 而不是 xml? [英] How to set to default to json instead of xml in jersey?

查看:20
本文介绍了如何在球衣中将默认设置为 json 而不是 xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 jersey jersey.java.net 当 URI 中没有接受标头或 .xml 后缀时,如何将 JSON 设置为默认序列化而不是 XML?

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?

推荐答案

您可以在@Produces 注解中为每个媒体类型分配质量指标.即,如果允许 XML 和 JSON,您可以执行以下操作以使 Jersey 更喜欢 JSON:

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"})

这篇关于如何在球衣中将默认设置为 json 而不是 xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆