如何使用 Jackson ObjectMapper 2.12 启用 ALLOW_NON_NUMERIC_NUMBERS?

How to enable ALLOW_NON_NUMERIC_NUMBERS with Jackson ObjectMapper 2.12?

这行代码给出弃用警告:

mapper.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);

这不能编译

mapper.configure(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS, true);

因为 JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS 不是 ObjectMapper 支持的四种 Feature 类型中任何一种的子类。

在 Jackson 2.12 中启用此功能的正确做法是什么?

似乎没有任何 API 接受 JacksonFeatureJsonReadFeature 作为参数。

DeserializationConfig 接受 FormatFeature 作为参数,但是在通过调用 withFeatures() 获取新实例后,您无法更改 ObjectMapper 的 属性。

唯一的解决方案似乎是从 JsonReadFeature 中删除该功能,然后不再弃用:

mapper.enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS.mappedFeature());

(注意枚举末尾的方法调用)。