且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

强制 Jackson 反序列化为特定的原始类型

更新时间:2023-01-16 21:55:07

如果类型声明为 java.lang.Object,Jackson 使用自然"映射,如果值适合 32 位,则使用整数.除了自定义处理程序之外,您还必须强制包含类型信息(通过在字段/getter 旁边添加 @JsonTypeInfo;或启用所谓的默认类型").

If type is declared as java.lang.Object, Jackson uses 'natural' mapping which uses Integer if value fits in 32 bits. Aside from custom handlers you would have to force inclusion of type information (either by adding @JsonTypeInfo next to field / getter; or by enabling so-called "default typing").