在 Jackson 的 ObjectMapper 中默认使用数组而不是 ArrayList
默认情况下,Jackson 的 ObjectMapper 将未知列表反序列化为 ArrayList,是否可以使用 String[] 代替?
class SomeBean {
Object[] items;
}
例如,此 JSON 导致 items[0] 的类型为 ArrayList:
{"items":[["a", "b"]]}
By default, Jackson's ObjectMapper de-serialises unknown lists as ArrayList, can it be made to use String[] instead?
class SomeBean {
Object[] items;
}
For example, this JSON results in the type of items[0] being ArrayList:
{"items":[["a", "b"]]}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前还没有,但如果您想看到此类功能,您可以通过在 Jackson JIRA (http://jira.codehaus.org/browse/JACKSON) 创建功能请求来建议它。实施应该相当简单;由“DeserializationConfig.Feature.JSON_ARRAYS_AS_JAVA_ARRAYS”(或其他)之类的东西启用。
我在这里假设您希望看到一个 Object[],因为它不能保证内容都是字符串(可能有数字、字符串、布尔值、列表/映射等)。
Not currently, although if you would like to see such feature, you could suggest it by creating a feature request at Jackson JIRA (http://jira.codehaus.org/browse/JACKSON). Implementation should be rather simple; enabled by something like 'DeserializationConfig.Feature.JSON_ARRAYS_AS_JAVA_ARRAYS' (or whatever).
I assume here that you would like to see an Object[], since it can not be guaranteed that contents are all Strings (could have Numbers, Strings, Booleans, lists/maps etc).