Example usage for com.fasterxml.jackson.databind.jsontype TypeResolverBuilder typeProperty

List of usage examples for com.fasterxml.jackson.databind.jsontype TypeResolverBuilder typeProperty

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.jsontype TypeResolverBuilder typeProperty.

Prototype

public abstract T typeProperty(String paramString);

Source Link

Usage

From source file:org.carewebframework.common.JSONUtil.java

/**
 * Initializes a mapper in a thread-safe way.
 * //from w  w  w.j  a v a2  s  .  c  o m
 * @return The initialized mapper.
 */
private static ObjectMapper initMapper(String typeProperty) {
    synchronized (mappers) {
        ObjectMapper mapper = mappers.get(typeProperty);
        if (mapper == null) {
            mapper = new ObjectMapper();
            TypeResolverBuilder<?> typer = new CWTypeResolverBuilder();
            typer = typer.init(JsonTypeInfo.Id.CUSTOM, new CWTypedIdResolver(mapper));
            typer = typer.inclusion(JsonTypeInfo.As.PROPERTY);
            typer = typer.typeProperty(typeProperty);
            mapper.setDefaultTyping(typer);
            mappers.put(typeProperty, mapper);
        }

        return mapper;
    }
}