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
基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01