@Override @Deprecated // since 2.8 public JavaType resolveType(java.lang.reflect.Type jdkType) { if (jdkType == null) { return null; } return _config.getTypeFactory().constructType(jdkType, _type.getBindings()); }
protected String idFromClass(Class<?> clazz) { if (clazz == null) { return null; } Class<?> cls = _typeFactory.constructType(clazz).getRawClass(); final String key = cls.getName(); String name; synchronized (_typeToId) { name = _typeToId.get(key); if (name == null) { // 24-Feb-2011, tatu: As per [JACKSON-498], may need to dynamically look up name // can either throw an exception, or use default name... if (_config.isAnnotationProcessingEnabled()) { BeanDescription beanDesc = _config.introspectClassAnnotations(cls); name = _config.getAnnotationIntrospector().findTypeName(beanDesc.getClassInfo()); } if (name == null) { // And if still not found, let's choose default? name = _defaultTypeId(cls); } _typeToId.put(key, name); } } return name; }
Class<?> cls = t.getType(); String id = t.hasName() ? t.getName() : _defaultTypeId(cls); if (forSer) { typeToId.put(cls.getName(), id); if (cls.isAssignableFrom(prev.getRawClass())) { // nope, more generic (or same) continue; idToType.put(id, config.constructType(cls));
/** * Accessor for getting bean description that only contains immediate class * annotations: ones from the class, and its direct mix-in, if any, but * not from super types. */ public BeanDescription introspectDirectClassAnnotations(Class<?> cls) { return introspectDirectClassAnnotations(constructType(cls)); }
public CreatorCollector(BeanDescription beanDesc, MapperConfig<?> config) { _beanDesc = beanDesc; _canFixAccess = config.canOverrideAccessModifiers(); _forceAccess = config .isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS); }
/** * Accessor for getting bean description that only contains class * annotations: useful if no getter/setter/creator information is needed. */ public BeanDescription introspectClassAnnotations(Class<?> cls) { return introspectClassAnnotations(constructType(cls)); }
AnnotatedMember property, JavaType baseType) final AnnotationIntrospector ai = config.getAnnotationIntrospector(); Class<?> rawBase = (baseType == null) ? property.getRawType() : baseType.getRawClass(); for (NamedType subtype : _registeredSubtypes) { if (rawBase.isAssignableFrom(subtype.getType())) { // yes AnnotatedClass curr = AnnotatedClassResolver.resolveWithoutSuperTypes(config, subtype.getType()); _collectAndResolve(curr, subtype, config, ai, collected); Collection<NamedType> st = ai.findSubtypes(property); if (st != null) { for (NamedType nt : st) { AnnotatedClass ac = AnnotatedClassResolver.resolveWithoutSuperTypes(config, nt.getType()); _collectAndResolve(ac, nt, config, ai, collected);
@Override public BasicBeanDescription forClassAnnotations(MapperConfig<?> cfg, JavaType type, MixInResolver r) { boolean useAnnotations = cfg.isAnnotationProcessingEnabled(); AnnotatedClass ac = AnnotatedClass.construct(type.getRawClass(), (useAnnotations ? cfg.getAnnotationIntrospector() : null), r); return BasicBeanDescription.forOtherUse(cfg, type, ac); }
public Class<?> materializeGenericType(MapperConfig<?> config, JavaType type) { Class<?> cls = type.getRawClass(); // Two-phase processing here; first construct concrete intermediate type: String abstractName = _defaultPackage+"abstract." +cls.getName()+"_TYPE_RESOLVE"; byte[] code = buildAbstractBase(type, abstractName); Class<?> raw = _classLoader.loadAndResolve(abstractName, code, cls); // and only with that intermediate non-generic type, do actual materialization AnnotatedClass ac = AnnotatedClassResolver.resolve(config, config.getTypeFactory().constructType(raw), config); return materializeRawType(config, ac); }
/** * Helper method that will construct {@link JavaType} for given * raw class. * This is a simple short-cut for: *<pre> * getTypeFactory().constructType(cls); *</pre> */ public final JavaType constructType(Class<?> cls) { return getTypeFactory().constructType(cls); }
final TypeFactory tf = config.getTypeFactory(); if (type.hasRawClass(serClass)) { type = type.withStaticTyping(); } else { Class<?> currRaw = type.getRawClass(); try { type = tf.constructGeneralizedType(type, serClass); } else if (currRaw.isAssignableFrom(serClass)) { // specialization, ok as well type = tf.constructSpecializedType(type, serClass); } else if (_primitiveAndWrapper(currRaw, serClass)) { keyType = tf.constructGeneralizedType(keyType, keyClass); } else if (currRaw.isAssignableFrom(keyClass)) { // specialization, ok as well keyType = tf.constructSpecializedType(keyType, keyClass);
protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerialization, JavaType type, AnnotatedClass classDef, String mutatorPrefix) { _config = config; _stdBeanNaming = config.isEnabled(MapperFeature.USE_STD_BEAN_NAMING); _forSerialization = forSerialization; _type = type; _classDef = classDef; _mutatorPrefix = (mutatorPrefix == null) ? "set" : mutatorPrefix; if (config.isAnnotationProcessingEnabled()) { _useAnnotations = true; _annotationIntrospector = _config.getAnnotationIntrospector(); } else { _useAnnotations = false; _annotationIntrospector = AnnotationIntrospector.nopInstance(); } _visibilityChecker = _config.getDefaultVisibilityChecker(type.getRawClass(), classDef); }
final TypeFactory tf = config.getTypeFactory(); if (baseType.getContentType() == null) { // non-container/-structured types, usually scalar: if (baseType.hasRawClass(deserClass)) { // no change return baseType; if (!baseType.getRawClass().isAssignableFrom(deserClass)) { return baseType; return tf.constructSpecializedType(baseType, deserClass); } catch (IllegalArgumentException iae) { throw new JsonMappingException(null, contentType = tf.constructSpecializedType(contentType, deserClass); return baseType.withContentType(contentType); } catch (IllegalArgumentException iae) {
AnnotatedClassResolver(MapperConfig<?> config, JavaType type, MixInResolver r) { _config = config; _type = type; _class = type.getRawClass(); _mixInResolver = r; _bindings = type.getBindings(); _intr = config.isAnnotationProcessingEnabled() ? config.getAnnotationIntrospector() : null; _primaryMixin = _config.findMixInClassFor(_class); }
final TypeFactory tf = config.getTypeFactory(); if (baseType.getContentType() == null) { // non-container/-structured types, usually scalar: if (!serClass.isAssignableFrom(baseType.getRawClass())) { return baseType; if (baseType.hasRawClass(serClass)) { return tf.constructGeneralizedType(baseType, serClass); } catch (IllegalArgumentException iae) { throw new JsonMappingException(null, } else { try { contentType = tf.constructGeneralizedType(contentType, serClass); } catch (IllegalArgumentException iae) { throw new JsonMappingException(null,
@Override public JsonInclude.Value findPropertyInclusion(MapperConfig<?> config, Class<?> baseType) { JsonInclude.Value v0 = config.getDefaultInclusion(baseType, _type.getRawClass()); AnnotationIntrospector intr = config.getAnnotationIntrospector(); if ((intr == null) || (_member == null)) { return v0; } JsonInclude.Value v = intr.findPropertyInclusion(_member); if (v == null) { return v0; } return v0.withOverrides(v); }
@Override public BasicBeanDescription forDirectClassAnnotations(MapperConfig<?> cfg, JavaType type, MixInResolver r) { boolean useAnnotations = cfg.isAnnotationProcessingEnabled(); AnnotationIntrospector ai = cfg.getAnnotationIntrospector(); AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(type.getRawClass(), (useAnnotations ? ai : null), r); return BasicBeanDescription.forOtherUse(cfg, type, ac); }
final TypeFactory tf = config.getTypeFactory(); if ((valueClass != null) && !type.hasRawClass(valueClass) && !_primitiveAndWrapper(type, valueClass)) { try { type = tf.constructSpecializedType(type, valueClass); } catch (IllegalArgumentException iae) { throw new JsonMappingException(null, if (type.isMapLikeType()) { JavaType keyType = type.getKeyType(); final Class<?> keyClass = (jsonDeser == null) ? null : _classIfExplicit(jsonDeser.keyAs()); if ((keyClass != null) && !_primitiveAndWrapper(keyType, keyClass)) { try { keyType = tf.constructSpecializedType(keyType, keyClass); type = ((MapLikeType) type).withKeyType(keyType); } catch (IllegalArgumentException iae) { && !_primitiveAndWrapper(contentType, contentClass)) { try { contentType = tf.constructSpecializedType(contentType, contentClass); type = type.withContentType(contentType); } catch (IllegalArgumentException iae) {
/** * Method called to find subtypes for a specific type (class), using * type id as the unique key (in case of conflicts). */ protected void _collectAndResolveByTypeId(AnnotatedClass annotatedType, NamedType namedType, MapperConfig<?> config, Set<Class<?>> typesHandled, Map<String,NamedType> byName) { final AnnotationIntrospector ai = config.getAnnotationIntrospector(); if (!namedType.hasName()) { String name = ai.findTypeName(annotatedType); if (name != null) { namedType = new NamedType(namedType.getType(), name); } } if (namedType.hasName()) { byName.put(namedType.getName(), namedType); } // only check subtypes if this type hadn't yet been handled if (typesHandled.add(namedType.getType())) { Collection<NamedType> st = ai.findSubtypes(annotatedType); if (st != null && !st.isEmpty()) { for (NamedType subtype : st) { AnnotatedClass subtypeClass = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), config); _collectAndResolveByTypeId(subtypeClass, subtype, config, typesHandled, byName); } } } }
@Override public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config, AnnotatedClass type) { final AnnotationIntrospector ai = config.getAnnotationIntrospector(); HashMap<NamedType, NamedType> subtypes = new HashMap<NamedType, NamedType>(); // then consider registered subtypes (which have precedence over annotations) if (_registeredSubtypes != null) { Class<?> rawBase = type.getRawType(); for (NamedType subtype : _registeredSubtypes) { // is it a subtype of root type? if (rawBase.isAssignableFrom(subtype.getType())) { // yes AnnotatedClass curr = AnnotatedClassResolver.resolveWithoutSuperTypes(config, subtype.getType()); _collectAndResolve(curr, subtype, config, ai, subtypes); } } } // and then check subtypes via annotations from base type (recursively) NamedType rootType = new NamedType(type.getRawType(), null); _collectAndResolve(type, rootType, config, ai, subtypes); return new ArrayList<NamedType>(subtypes.values()); }