- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有抽象类的列表
List<Messaging> data;
Messaging 是一个抽象类,另外 3 个类扩展了这个类。
例如,
Message class extends Messaging
Product class extends Messaging
Filter class extends Messaging
我正在添加上面列表中的所有消息
我在 Messaging 类上使用了 @JsonTypeInfo,如下所示:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY)
@JsonSubTypes({
@Type(value = Message.class, name = "message"),
@Type(value = Filter.class, name = "filter"),
@Type(value = Product.class , name = "product")})
当我使用 jackson 将此 Java 对象序列化为 JSON 时,我得到如下值:
{
"@type": "message",
"type": "text",
"value": "Is this the information you need"
}
我希望我的值(value)如下:
"message" : {
"type": "text",
"value": "Is this the information you need"
}
如何将多态对象列表序列化到不同的节点?
最佳答案
更改 JsonTypeInfo
以包含为 WRAPPER_OBJECT
。
例如:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include=As.WRAPPER_OBJECT)
关于java - 将多态 json 序列化为特定的 jsonnode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45833715/
我正在使用 jackson 库。我有很多 java 对象,它们只不过是 jsonNode 的包装器。因此想要将这些 jsonNodes 列表转换为单个 jsonNode。我怎样才能做到这一点。我试过这
我有主 JsonNode,{{k1:v1} = s1,{k2:v2} = s2,{k3:v3} = s3} 我单独获取一个节点键 {k1 : v1} 并将其分配给另一个变量并将其更新为 {k1 : n
我正在用 Java 编写 Play 2.3.2 应用程序。 在我的应用程序中,我调用了用 Scala 编写的其他模块的方法。 此方法返回一个 Json 响应,我尝试使用 WS 获取该响应。 这是我的方
我在写这篇文章时需要一些指导,以便我理解这个概念: 基本上,我需要在 String 和 JsonNode 之间进行转换,并且我已经看到了一个说明要做什么的答案,但作为新手开发人员,我不确定这意味着什么
我有以下 Json { "Parent": { "pk1": "pv1", "pk2": "pv2", "Child": {
我是 Java 菜鸟,正在努力进行类型转换。我有一个如下所示的 JSON 对象: [ { "A":{ "B":{
我遇到了转换错误,但不知道如何解决。 //get my json file as Map Map cm = null; try { cm = mapper.readValu
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 3 年前。 我需要获取此 arrayNode
我刚刚从 sourceforge.net 安装了 libjson。我尝试执行一个简单的程序但是我得到了这个错误 ‘JSONNode’ was not declared in this scope 这是
我在 Java 中使用 Jackson 库生成了以下 Json: { "name": "name1", "version": "0.0.1", "storage": {
我有以下 JSON 文件。 { "data": { "k1": "v1", "k2": "v2", ... } } 有什么方法可以将这些键和值作为 Map 获取吗?使用
通过 Play WS API,我得到了一个 Response 对象。因为它包含我调用的 JSON response.asJson() 这工作得很好。现在我想以 pretty-print 版本返回这个
我有这个json: { "text":[ {"a":1}, {"b":2} ] } 我有这个代码: JsonNode jsonNode = (new O
我正在尝试更新 expiryDate将嵌套的 JsonObject 中的变量设置为当前日期,JSON 的结构如下: { "expiryDate" : { "type" : "S
如何将 JsonNode 作为 java.email 中的电子邮件附件作为 json 文件发送 // Json node bit JsonNode requestBody = request().
考虑以下 Java 类定义。 CrudOperation.java: package com.cyberfront.test.json.nll.demonstration; import com.fa
我有一个类: Class myClass { @JsonProperty("status") boolean status; public boolean getStatus(
我正在从 cassandra 表中读取数据记录。创建我构建的 Java 对象。使用我从数据记录中获得的值设置所有值(我使用 jackson 从记录中获取这些值)。当我查看 json 请求时,我看到一个
我有一个Jackson子类型 ObjectNode 的 JsonNode: ObjectNode node = parent.path('somepath'); node 有许多子字段,例如您在这个
我有以下代码,它从 JsonNode 返回 string 的 list: public static List asList(final JsonNode jsonNode) {
我是一名优秀的程序员,十分优秀!