/** * Helper method called to check if a class or method * has annotation that tells which class to use for deserialization. * Returns null if no such annotation found. */ protected JsonDeserializer<Object> findDeserializerFromAnnotation(DeserializationConfig config, Annotated ann, BeanProperty property) throws JsonMappingException { Object deserDef = config.getAnnotationIntrospector().findDeserializer(ann); if (deserDef != null) { return _constructDeserializer(config, ann, property, deserDef); } return null; }
@Override public JsonDeserializer<?> createCollectionLikeDeserializer(DeserializationConfig config, DeserializerProvider p, CollectionLikeType type, BeanProperty property) throws JsonMappingException { // First: global defaulting: type = (CollectionLikeType) mapAbstractType(config, type); Class<?> collectionClass = type.getRawClass(); BasicBeanDescription beanDesc = config.introspectClassAnnotations(collectionClass); // Explicit deserializer to use? (@JsonDeserialize.using) JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; } // If not, any type modifiers? (@JsonDeserialize.as) type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); JavaType contentType = type.getContentType(); // Very first thing: is deserializer hard-coded for elements? JsonDeserializer<Object> contentDeser = contentType.getValueHandler(); // Then optional type info (1.5): if type has been resolved, we may already know type deserializer: TypeDeserializer contentTypeDeser = contentType.getTypeHandler(); // but if not, may still be possible to find: if (contentTypeDeser == null) { contentTypeDeser = findTypeDeserializer(config, contentType, property); } return _findCustomCollectionLikeDeserializer(type, config, p, beanDesc, property, contentTypeDeser, contentDeser); }
JsonDeserializer<?> custom = _findCustomArrayDeserializer(type, config, p, property, null, null); if (custom != null) { return custom; elemTypeDeser = findTypeDeserializer(config, elemType, property); JsonDeserializer<?> custom = _findCustomArrayDeserializer(type, config, p, property, elemTypeDeser, contentDeser); if (custom != null) { return custom;
type = (MapLikeType) mapAbstractType(config, type); BasicBeanDescription beanDesc = config.introspectForCreation(type); JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); contentTypeDeser = findTypeDeserializer(config, contentType, property); return _findCustomMapLikeDeserializer(type, config, p, beanDesc, property, keyDes, contentTypeDeser, contentDeser);
type = (CollectionType) mapAbstractType(config, type); JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); contentTypeDeser = findTypeDeserializer(config, contentType, property); JsonDeserializer<?> custom = _findCustomCollectionDeserializer(type, config, p, beanDesc, property, contentTypeDeser, contentDeser); if (custom != null) { createEnumDeserializer(config, p, contentType, property)); ValueInstantiator inst = findValueInstantiator(config, beanDesc);
type = (MapType) mapAbstractType(config, type); JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); contentTypeDeser = findTypeDeserializer(config, contentType, property); JsonDeserializer<?> custom = _findCustomMapDeserializer(type, config, p, beanDesc, property, keyDes, contentTypeDeser, contentDeser); createEnumDeserializer(config, p, keyType, property), contentDeser); ValueInstantiator inst = findValueInstantiator(config, beanDesc); MapDeserializer md = new MapDeserializer(type, inst, keyDes, contentDeser, contentTypeDeser); md.setIgnorableProperties(config.getAnnotationIntrospector().findPropertiesToIgnore(beanDesc.getClassInfo()));
type = (CollectionType) mapAbstractType(config, type); JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); contentTypeDeser = findTypeDeserializer(config, contentType, property); JsonDeserializer<?> custom = _findCustomCollectionDeserializer(type, config, p, beanDesc, property, contentTypeDeser, contentDeser); if (custom != null) { return new EnumSetDeserializer(constructEnumResolver(contentType.getRawClass(), config)); ValueInstantiator inst = findValueInstantiator(config, beanDesc);
type = (MapType) mapAbstractType(config, type); JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); contentTypeDeser = findTypeDeserializer(config, contentType, property); JsonDeserializer<?> custom = _findCustomMapDeserializer(type, config, p, beanDesc, property, keyDes, contentTypeDeser, contentDeser); throw new IllegalArgumentException("Can not construct EnumMap; generic (key) type not available"); return new EnumMapDeserializer(constructEnumResolver(kt, config), contentDeser); ValueInstantiator inst = findValueInstantiator(config, beanDesc); MapDeserializer md = new MapDeserializer(type, inst, keyDes, contentDeser, contentTypeDeser); md.setIgnorableProperties(config.getAnnotationIntrospector().findPropertiesToIgnore(beanDesc.getClassInfo()));
type = (MapType) mapAbstractType(config, type); JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); contentTypeDeser = findTypeDeserializer(config, contentType, property); JsonDeserializer<?> custom = _findCustomMapDeserializer(type, config, p, beanDesc, property, keyDes, contentTypeDeser, contentDeser); throw new IllegalArgumentException("Can not construct EnumMap; generic (key) type not available"); return new EnumMapDeserializer(constructEnumResolver(kt, config), contentDeser); md.setCreators(findMapCreators(config, beanDesc)); return md;
JsonDeserializer<?> des = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (des != null) { return des; JsonDeserializer<?> custom = _findCustomEnumDeserializer(enumClass, config, beanDesc, property); if (custom != null) { return custom; return new EnumDeserializer(constructEnumResolver(enumClass, config));
/** * Method that will construct a property object that represents * a logical property passed via Creator (constructor or static * factory method) */ protected SettableBeanProperty constructCreatorProperty(DeserializationConfig config, BasicBeanDescription beanDesc, String name, int index, AnnotatedParameter param) throws JsonMappingException { JavaType t0 = config.getTypeFactory().constructType(param.getParameterType(), beanDesc.bindingsForBeanType()); BeanProperty.Std property = new BeanProperty.Std(name, t0, beanDesc.getClassAnnotations(), param); JavaType type = resolveType(config, beanDesc, t0, param, property); if (type != t0) { property = property.withType(type); } // Is there an annotation that specifies exact deserializer? JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, param, property); // If yes, we are mostly done: type = modifyTypeByAnnotation(config, param, type, name); TypeDeserializer typeDeser = findTypeDeserializer(config, type, property); SettableBeanProperty prop = new SettableBeanProperty.CreatorProperty(name, type, typeDeser, beanDesc.getClassAnnotations(), param, index); if (deser != null) { prop.setValueDeserializer(deser); } return prop; } }
/** * Method that will construct a property object that represents * a logical property passed via Creator (constructor or static * factory method) */ protected SettableBeanProperty constructCreatorProperty(DeserializationConfig config, BasicBeanDescription beanDesc, String name, int index, AnnotatedParameter param) throws JsonMappingException { JavaType type = resolveType(config, beanDesc, param.getParameterType(), param); // Is there an annotation that specifies exact deserializer? JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, param); // If yes, we are mostly done: if (deser != null) { SettableBeanProperty.CreatorProperty prop = new SettableBeanProperty.CreatorProperty(name, type, beanDesc.getBeanClass(), index); prop.setValueDeserializer(deser); return prop; } // Otherwise may have other type specifying annotations type = modifyTypeByAnnotation(config, param, type); return new SettableBeanProperty.CreatorProperty(name, type, beanDesc.getBeanClass(), index); } }
JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo()); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type); md.setCreators(findMapCreators(config, beanDesc)); md.validateCreators(); return md;
JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo()); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type);
@Override public JsonDeserializer<?> createTreeDeserializer(DeserializationConfig config, DeserializerProvider p, JavaType nodeType, BeanProperty property) throws JsonMappingException { @SuppressWarnings("unchecked") Class<? extends JsonNode> nodeClass = (Class<? extends JsonNode>) nodeType.getRawClass(); // 23-Nov-2010, tatu: Custom deserializer? JsonDeserializer<?> custom = _findCustomTreeNodeDeserializer(nodeClass, config, property); if (custom != null) { return custom; } return JsonNodeDeserializer.getDeserializer(nodeClass); }
/** * Factory method for constructing serializers of {@link Enum} types. */ @Override @SuppressWarnings("unchecked") public JsonDeserializer<?> createEnumDeserializer(DeserializationConfig config, Class<?> enumClass, DeserializerProvider p) throws JsonMappingException { /* 18-Feb-2009, tatu: Must first check if we have a class annotation * that should override default deserializer */ BasicBeanDescription beanDesc = config.introspectClassAnnotations(enumClass); JsonDeserializer<Object> des = findDeserializerFromAnnotation(config, beanDesc.getClassInfo()); if (des != null) { return des; } JsonDeserializer<?> d2 = new EnumDeserializer(EnumResolver.constructUnsafe(enumClass, config.getAnnotationIntrospector())); return (JsonDeserializer<Object>) d2; }
type = (MapLikeType) mapAbstractType(config, type); BasicBeanDescription beanDesc = config.introspectForCreation(type); JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); contentTypeDeser = findTypeDeserializer(config, contentType, property); return _findCustomMapLikeDeserializer(type, config, p, beanDesc, property, keyDes, contentTypeDeser, contentDeser);
type = (CollectionType) mapAbstractType(config, type); JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); contentTypeDeser = findTypeDeserializer(config, contentType, property); JsonDeserializer<?> custom = _findCustomCollectionDeserializer(type, config, p, beanDesc, property, contentTypeDeser, contentDeser); if (custom != null) { createEnumDeserializer(config, p, contentType, property)); ValueInstantiator inst = findValueInstantiator(config, beanDesc);
type = (MapType) mapAbstractType(config, type); JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); JavaType keyType = type.getKeyType(); JavaType contentType = type.getContentType(); contentTypeDeser = findTypeDeserializer(config, contentType, property); JsonDeserializer<?> custom = _findCustomMapDeserializer(type, config, p, beanDesc, property, keyDes, contentTypeDeser, contentDeser); createEnumDeserializer(config, p, keyType, property), contentDeser); ValueInstantiator inst = findValueInstantiator(config, beanDesc); MapDeserializer md = new MapDeserializer(type, inst, keyDes, contentDeser, contentTypeDeser); md.setIgnorableProperties(config.getAnnotationIntrospector().findPropertiesToIgnore(beanDesc.getClassInfo()));
type = (CollectionType) mapAbstractType(config, type); JsonDeserializer<Object> deser = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (deser != null) { return deser; type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); contentTypeDeser = findTypeDeserializer(config, contentType, property); JsonDeserializer<?> custom = _findCustomCollectionDeserializer(type, config, p, beanDesc, property, contentTypeDeser, contentDeser); if (custom != null) { return new EnumSetDeserializer(constructEnumResolver(contentType.getRawClass(), config));