aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/fasterxml/jackson/databind/introspect/TypeResolutionContext.java
blob: 405a5e9c21ecd49dcec674cdd831c0a14bc14cb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.fasterxml.jackson.databind.introspect;

import java.lang.reflect.Type;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeBindings;
import com.fasterxml.jackson.databind.type.TypeFactory;

/**
 * Interface that defines API used by members (like {@link AnnotatedMethod})
 * to dynamically resolve types they have.
 *
 * @since 2.7
 */
public interface TypeResolutionContext {
    public JavaType resolveType(Type t);

    public static class Basic
        implements TypeResolutionContext
    {
        private final TypeFactory _typeFactory;
        private final TypeBindings _bindings;

        public Basic(TypeFactory tf, TypeBindings b) {
            _typeFactory = tf;
            _bindings = b;
        }

        @Override
        public JavaType resolveType(Type type) {
            // 15-Jun-2020, tatu: As a consequence of [databind#2796], need to
            //    AVOID passing bindings for raw, type-erased cases, as otherwise
            //    we seem to get odd "generic Long" cases (for Mr Bean module at least)
            if (type instanceof Class<?>) {
                return _typeFactory.constructType(type);
            }
            return _typeFactory.constructType(type, _bindings);
        }

        /*// debugging
        @Override
        public String toString() {
            return "[TRC.Basic, bindings: "+_bindings+"]";
        }
        */
    }
}