[英]Flattening nested attributes in Jackson
I have the need of defining a flat POJO that maps its (flat) attributes to a nested object in its JSON specification.我需要定义一个平面 POJO,将其(平面)属性映射到其 JSON 规范中的嵌套对象。 Better explain with code最好用代码解释
{
"offset": 0,
"pageSize": 10,
"filter": {
"key1":"value1",
"key2": true,
....
}
}
My POJO shall look like the following:我的 POJO 应如下所示:
public class Pojo {
private int offset;
private int pageSize;
private String key1;
private boolean key2;
}
So far I have tried annotating those key
properties with @JsonProperty
with its value
attribute到目前为止,我已经尝试使用@JsonProperty
及其value
属性注释这些key
属性
@JsonProperty("filter.key1")
private String key1;
But when I went into the MVC controller those properties, though set in JSON, were null in the decoded POJO.但是当我进入 MVC 控制器时,这些属性虽然在 JSON 中设置,但在解码的 POJO 中为空。
How can I fix this?我怎样才能解决这个问题? What did I do wrong?我做错了什么?
I absolutely don't want to create nested subclasses我绝对不想创建嵌套的子类
Might be currently impossible.目前可能是不可能的。
This because Jackson currently supports @JacksonUnwrapped
for the opposite case, but no @JacksonWrapped
这是因为杰克逊目前支持@JacksonUnwrapped
用于相反的情况,但不支持@JacksonWrapped
Feature request: https://github.com/FasterXML/jackson-annotations/issues/42功能请求: https : //github.com/FasterXML/jackson-annotations/issues/42
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.