Change field case with an ObjectMapper

前端 未结 4 854
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 02:24

I think I need to create a specialist ObjectMapper and cannot find any sample code to start the process.

The creator of the JSON is using .Net

4条回答
  •  孤城傲影
    2020-12-30 02:39

    This problem could be solved from Jackson 2.5.0 like this:

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
    

    From the javadoc:

    com.fasterxml.jackson.databind.MapperFeature.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.

    Since: 2.5

提交回复
热议问题