Remove quot;typequot; from JSON output jersey moxy(删除“类型从 JSON 输出球衣 moxy)
问题描述
如何从我拥有的 JSON 输出中删除 type.我有一个包含 REST 服务输出的类/bean.我正在使用 jersey-media-moxy 进行转换.
How to remove the type from the JSON output that I have. I have a class/bean that contains output of a REST service.I'm using jersey-media-moxy to do the conversion.
服务
@Resource
public interface MyBeanResource
{
@GET
@Path("/example")
@Produces( MediaType.APPLICATION_JSON )
public Bean getBean();
}
豆子
@XmlRootElement
class Bean
{
String a;
}
我想添加一些功能(用于使用构造函数初始化 bean)
I want to add some functionality (for initializing the bean using the constructor)
class BeanImpl extends Bean
{
BeanImpl(OtherClass c)
{
a = c.toString()
}
}
输出的 JSON 是:
The outputted JSON is:
{type:"beanImpl", a:"somevalue"}
我不想在我的 JSON 中使用 type.我该如何配置?
I do not want the type in my JSON. How can I configure this?
推荐答案
我在扩展一个类并生成 JSON 时遇到了同样的错误——但只针对顶级(根)类.作为一种解决方法,我使用 @XmlType(name="") 注释我的 子类,这会阻止生成的 type 属性出现在我的 JSON 中.
I get the same error when I extend a class and generate JSON -- but only for a top-level (root) class. As a workaround, I annotate my subclass with @XmlType(name=""), which prevents the generated type property from appearing in my JSON.
Blaise,我不确定为什么会这样.有什么想法吗?
Blaise, I'm not sure why this works. Any thoughts?
这篇关于删除“类型"从 JSON 输出球衣 moxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:删除“类型"从 JSON 输出球衣 moxy
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
