“放松";杰克逊(Jackson)的字段名称 [英] "Relaxed" fields names for Jackson
问题描述
我正在研究Jackson
配置,我想知道是否有任何选项可以反序列化不同种类的字段模式.
I'm working on Jackson
configuration and I wonder if there is any option to deserialise different kinds of field patterns.
例如,我有一个对象:
class DeserializeIt {
String fieldOne;
String fieldOneAndHalf;
String fieldTwo;
String fieldThree;
String fieldFour;
//getters setters etc.
}
我的有效载荷低于JSON
:
{
"fieldOne" : "value1",
"field_ONE-and_Half": "value15",
"FIELD_TWO": "value2",
"FIELD_THREE" : "value3",
"field_four": "value4"
}
我想将所有这些字段名称反序列化为驼峰式大小写.
I would like to deserialize all these field names to camel case without an exception.
我尝试创建自定义PropertyNamingStrategy
,但是它从另一个方向出发:它不会将定界字段转换为驼峰式大小写,而是尝试转换对象字段并在已解析的字符串中搜索它们.
I tried to create my custom PropertyNamingStrategy
but it goes from another direction: it does not convert delimitered fields to camel case, it tries to convert the objects fields and search for them in the parsed string.
而且由于我无法传递可能的字符串列表而不是一个变体(fieldOne
可以变成field-one
,field_one
,field-ONE
等),所以这不起作用.
And since I cannot pass a list of possible strings instead of one variation (fieldOne
can become field-one
, field_one
, field-ONE
etc.), this does not work.
您知道我还可以为这种轻松的反序列化配置什么吗?
Do you know what else could I configure for such a relaxed deserialization?
推荐答案
对自己有用的方法:我添加了一个AOP组件,该组件将传入对象的所有字段重命名为Camel案例.
What worked for myself: I added an AOP component that renames all the fields of incoming object into the Camel case.
这篇关于“放松";杰克逊(Jackson)的字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!