/** * Method called to find filter that is configured to be used with bean * serializer being built, if any. * * @since 1.7 */ protected Object findFilterId(SerializationConfig config, BasicBeanDescription beanDesc) { return config.getAnnotationIntrospector().findFilterId(beanDesc.getClassInfo()); }
protected Object getDefaultBean() { if (_defaultBean == null) { /* If we can fix access rights, we should; otherwise non-public * classes or default constructor will prevent instantiation */ _defaultBean = _beanDesc.instantiateBean(_config.isEnabled(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)); if (_defaultBean == null) { Class<?> cls = _beanDesc.getClassInfo().getAnnotated(); throw new IllegalArgumentException("Class "+cls.getName()+" has no default constructor; can not instantiate default bean value to support 'properties=JsonSerialize.Inclusion.NON_DEFAULT' annotation"); } } return _defaultBean; }
/** * Overridable method that can filter out properties. Default implementation * checks annotations class may have. */ protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config, BasicBeanDescription beanDesc, List<BeanPropertyWriter> props) { AnnotationIntrospector intr = config.getAnnotationIntrospector(); AnnotatedClass ac = beanDesc.getClassInfo(); String[] ignored = intr.findPropertiesToIgnore(ac); if (ignored != null && ignored.length > 0) { HashSet<String> ignoredSet = ArrayBuilders.arrayToSet(ignored); Iterator<BeanPropertyWriter> it = props.iterator(); while (it.hasNext()) { if (ignoredSet.contains(it.next().getName())) { it.remove(); } } } return props; }
if (result == null) { BasicBeanDescription desc = config.introspectClassAnnotations(type); AnnotatedClass ac = desc.getClassInfo(); result = intr.isIgnorableType(ac);
/** * Helper method that will check whether given raw type is marked as always ignorable * (for purpose of ignoring properties with type) */ protected boolean isIgnorableType(DeserializationConfig config, BasicBeanDescription beanDesc, Class<?> type, Map<Class<?>,Boolean> ignoredTypes) { Boolean status = ignoredTypes.get(type); if (status == null) { BasicBeanDescription desc = config.introspectClassAnnotations(type); status = config.getAnnotationIntrospector().isIgnorableType(desc.getClassInfo()); // We default to 'false', ie. not ignorable if (status == null) { status = Boolean.FALSE; } } return status; } }
@Override public String idFromValue(Object value) { Class<?> cls = value.getClass(); 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()) { BasicBeanDescription 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; }
AnnotatedClass ac = beanDesc.getClassInfo(); Object instDef = config.getAnnotationIntrospector().findValueInstantiator(ac); if (instDef != 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); }
/** * Helper method that handles configuration details when constructing serializers for * {@link java.util.Map} types. *<p> * Note: signature changed in 1.8, to take 'staticTyping' argument */ protected JsonSerializer<?> buildMapSerializer(SerializationConfig config, MapType type, BasicBeanDescription beanDesc, BeanProperty property, boolean staticTyping, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) { for (Serializers serializers : customSerializers()) { JsonSerializer<?> ser = serializers.findMapSerializer(config, type, beanDesc, property, keySerializer, elementTypeSerializer, elementValueSerializer); if (ser != null) { return ser; } } if (EnumMap.class.isAssignableFrom(type.getRawClass())) { return buildEnumMapSerializer(config, type, beanDesc, property, staticTyping, elementTypeSerializer, elementValueSerializer); } return MapSerializer.construct(config.getAnnotationIntrospector().findPropertiesToIgnore(beanDesc.getClassInfo()), type, staticTyping, elementTypeSerializer, property, keySerializer, elementValueSerializer); }
public synchronized SerializedString findRootName(Class<?> rootType, MapperConfig<?> config) { ClassKey key = new ClassKey(rootType); if (_rootNames == null) { _rootNames = new LRUMap<ClassKey,SerializedString>(20, 200); } else { SerializedString name = _rootNames.get(key); if (name != null) { return name; } } BasicBeanDescription beanDesc = (BasicBeanDescription) config.introspectClassAnnotations(rootType); AnnotationIntrospector intr = config.getAnnotationIntrospector(); AnnotatedClass ac = beanDesc.getClassInfo(); String nameStr = intr.findRootName(ac); // No answer so far? Let's just default to using simple class name if (nameStr == null) { // Should we strip out enclosing class tho? For now, nope: nameStr = rootType.getSimpleName(); } SerializedString name = new SerializedString(nameStr); _rootNames.put(key, name); return name; } }
JsonDeserializer<?> des = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (des != null) { return des;
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();
/** * Method called to construct a type serializer for values with given declared * base type. This is called for values other than those of bean property * types. */ @Override public TypeSerializer createTypeSerializer(SerializationConfig config, JavaType baseType, BeanProperty property) { BasicBeanDescription bean = config.introspectClassAnnotations(baseType.getRawClass()); AnnotatedClass ac = bean.getClassInfo(); AnnotationIntrospector ai = config.getAnnotationIntrospector(); TypeResolverBuilder<?> b = ai.findTypeResolver(config, ac, baseType); /* Ok: if there is no explicit type info handler, we may want to * use a default. If so, config object knows what to use. */ Collection<NamedType> subtypes = null; if (b == null) { b = config.getDefaultTyper(baseType); } else { subtypes = config.getSubtypeResolver().collectAndResolveSubtypes(ac, config, ai); } return (b == null) ? null : b.buildTypeSerializer(config, baseType, subtypes, property); }
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);
beanDesc.getClassInfo(), property); JsonSerializer<Object> keySerializer = findKeySerializer(config, beanDesc.getClassInfo(), property); if (mlt.isTrueMapType()) { return buildMapSerializer(config, (MapType) mlt, beanDesc, property, staticTyping,
JsonSerializer<?> ser = findSerializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (ser != null) { return (JsonSerializer<Object>) ser; JavaType type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), origType);
JsonDeserializer<Object> ad = findDeserializerFromAnnotation(config, beanDesc.getClassInfo(), property); if (ad != null) { return ad; JavaType newType = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), type, null); if (newType.getRawClass() != type.getRawClass()) { type = newType;
JsonSerialize.Typing t = intr.findSerializationTyping(beanDesc.getClassInfo()); if (t != null) { if (t == JsonSerialize.Typing.STATIC) {
vchecker = config.getAnnotationIntrospector().findAutoDetectVisibility(beanDesc.getClassInfo(), vchecker);
AnnotatedClass ac = bean.getClassInfo(); AnnotationIntrospector ai = config.getAnnotationIntrospector(); TypeResolverBuilder<?> b = ai.findTypeResolver(config, ac, baseType);