如何在球衣中将默认设置为 json 而不是 xml?球衣、设置为、中将、而不是

2023-09-07 08:49:59 作者:昏君作派

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