删除“类型”来自JSON输出泽西moxy [英] Remove "type" from JSON output jersey moxy
问题描述
如何从我拥有的JSON输出中删除类型
。我有一个包含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();
}
The Bean
@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是:
{type:beanImpl,a:somevalue}
我不想在我的JSON中输入类型
。我该如何配置?
I do not want the type
in my JSON. How can I configure this?
推荐答案
我在扩展类并生成JSON时遇到同样的错误 - 但只针对顶层(root)类。作为一种解决方法,我使用 @XmlType(name =)
注释我的子类,这会阻止生成的类型
属性出现在我的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!