Jetison JSON 自动更改数据类型
我正在使用 Resteasy 2.0.1.GA,因此 Resteasy-jettison-provider-1.2.GA 每当我有一个包含所有数字的 String 属性(即 String test="1111";)时,JSON 响应会将其显示为删除双引号后的数字。如果我将其更改为 String test="oneoneoneoneone"; JSON 响应会将其视为字符串并在响应中保留双引号。无论如何,是否可以让 Jettison 提供者根据数据类型而不是值来严格解释数据以进行响应?我也尝试了下面的 JAXB 注释,但仍然看到同样的问题。
@XmlElement(type=String.class)
private String text;
I'm using Resteasy 2.0.1.GA and thusly Resteasy-jettison-provider-1.2.GA and whenever I have a String property that contains all numbers (i.e. String test="1111";), the JSON response will display it as a number by removing the double quotes. If I change it to String test="oneoneoneoneone"; the JSON response will treat it as a String and keep the double quotes in the response. Is there anyway to have the Jettison provider strictly interpret the data to response based on its type and not its value? I tried the below JAXB annotation as well, but I still see the same issue.
@XmlElement(type=String.class)
private String text;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议改用基于 Jackson 的提供程序——Jettison 有足够的怪癖让生活变得相当困难(而且它不支持使用 JAXB 注释,即使处理必须通过 XML 接口)。
Jettison 可能有一个禁用隐式转换的设置(这个问题已在 jettison 用户列表中提及);因此,如果您更喜欢使用它,这可能是另一条路线。
I would recommend switching to using Jackson based provider -- Jettison has enough quirks to make life pretty difficult (and it does not support use of JAXB annotations, even though processing has to go through XML interfaces).
There may be a setting to disable implied conversions (this issue has been mention on jettison user's list) for Jettison; so if you prefer using it, this might be another route.