杰克逊(Jackson)的objectmapper()。writeValueasString()忽略以“ is_ is_”开头的变量
如果A有类似的匿名类,
val a = object {
val is_something = "some value"
val something = "other value"
}
并且将
println(ObjectMapper().writeValueAsString(a))
结果称为,
"{"something":"other value"}"
则对于以“ IS_”开头的所有变量,就是这样。为什么?
更正,它不会忽略它。它取下“ IS”,并将变量移至字符串的末端。因此,在这里结果
"{"something":"other value","_something":"some value"}"
仍然是,为什么要这样做呢?
If a have an anonymous class like:
val a = object {
val is_something = "some value"
val something = "other value"
}
and call
println(ObjectMapper().writeValueAsString(a))
the result would be
"{"something":"other value"}"
And it's like this for all variables that begin with "is_". Why?
Correction, it doesn't ignore it. It takes off the "is" and moves the variable to the end of the string. So here the result would be
"{"something":"other value","_something":"some value"}"
Still, why does it do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
杰克逊显然扫描您通过的班级
然后使用这些方法进行序列化和挑选化。
“获取”,“ set”,“ is”被消除,这些方法中仍然存在的内容将用作JSON字段。
因此,您的“ is_something”将其更改为“ _something”等等。
Jackson apparently scans the class that you pass in for getters and setters
and then use those methods for serialization and deserialization.
"Get", "Set", "is" are eliminated and what remains in those methods will be used as Json field.
Hence your "is_something" is changed into "_something" and so on.
通过在“ is_something”之上添加@jsonproperty并利用它来解决问题。
因此,该对象看起来
仍然不知道是什么原因引起了问题
The issue was solved by adding @JsonProperty on top of "is_something" and capitalizing it.
So the object would look like
Still have no idea what caused the problem