Case-insensitive JsonNode in Jackson

前端 未结 2 577
栀梦
栀梦 2021-01-19 14:39

I need to deserialize JSON objects and access the fields in a case-insensitive manner. Example:

String s = \"{\\\"FOO\\\": 123}\";
ObjectMapper mapper = new         


        
相关标签:
2条回答
  • 2021-01-19 15:20

    There is no automated way, but you could do it by creating custom JsonNodeFactory which creates custom ObjectNodes -- and then you can override method(s) used for adding and accessing entries.

    0 讨论(0)
  • 2021-01-19 15:20

    This feature is available as of 2.5 (Jan 2015):

    ACCEPT_CASE_INSENSITIVE_PROPERTIES

    Feature that will allow for more forgiving deserialization of incoming JSON. If enabled, the bean properties will be matched using their lower-case equivalents, meaning that any case-combination (incoming and matching names are canonicalized by lower-casing) should work. Note that there is additional performance overhead since incoming property names need to be lower-cased before comparison, for cases where there are upper-case letters. Overhead for names that are already lower-case should be negligible however.

    Feature is disabled by default.

    https://fasterxml.github.io/jackson-databind/javadoc/2.5/com/fasterxml/jackson/databind/MapperFeature.html

    0 讨论(0)
提交回复
热议问题