com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping#NON_FINAL源码实例Demo

下面列出了com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping#NON_FINAL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: redisson   文件: JsonJacksonCodec.java
protected void initTypeInclusion(ObjectMapper mapObjectMapper) {
    TypeResolverBuilder<?> mapTyper = new DefaultTypeResolverBuilder(DefaultTyping.NON_FINAL) {
        public boolean useForType(JavaType t) {
            switch (_appliesFor) {
            case NON_CONCRETE_AND_ARRAYS:
                while (t.isArrayType()) {
                    t = t.getContentType();
                }
                // fall through
            case OBJECT_AND_NON_CONCRETE:
                return (t.getRawClass() == Object.class) || !t.isConcrete();
            case NON_FINAL:
                while (t.isArrayType()) {
                    t = t.getContentType();
                }
                // to fix problem with wrong long to int conversion
                if (t.getRawClass() == Long.class) {
                    return true;
                }
                if (t.getRawClass() == XMLGregorianCalendar.class) {
                    return false;
                }
                return !t.isFinal(); // includes Object.class
            default:
                // case JAVA_LANG_OBJECT:
                return t.getRawClass() == Object.class;
            }
        }
    };
    mapTyper.init(JsonTypeInfo.Id.CLASS, null);
    mapTyper.inclusion(JsonTypeInfo.As.PROPERTY);
    mapObjectMapper.setDefaultTyping(mapTyper);
}
 
@Before
public void setUp() {
    builder = new ClassAliasTypeResolverBuilder(DefaultTyping.NON_FINAL);
}