/** * Method that can be called to modify access rights, by calling * {@link java.lang.reflect.AccessibleObject#setAccessible} on * the underlying annotated element. */ public final void fixAccess() { ClassUtil.checkAndFixAccess(getMember()); }
/** * Method called locate all members used for value injection (if any), * constructor {@link org.codehaus.jackson.map.deser.impl.ValueInjector} instances, and add them to builder. * * @since 1.9 */ protected void addInjectables(DeserializationConfig config, BasicBeanDescription beanDesc, BeanDeserializerBuilder builder) throws JsonMappingException { Map<Object, AnnotatedMember> raw = beanDesc.findInjectables(); if (raw != null) { boolean fixAccess = config.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS); for (Map.Entry<Object, AnnotatedMember> entry : raw.entrySet()) { AnnotatedMember m = entry.getValue(); if (fixAccess) { m.fixAccess(); // to ensure we can call it } builder.addInjectable(m.getName(), beanDesc.resolveType(m.getGenericType()), beanDesc.getClassAnnotations(), m, entry.getKey()); } } }
@Override public <A extends Annotation> A getAnnotation(Class<A> acls) { return _member.getAnnotation(acls); }
@Override public Object findInjectableValueId(AnnotatedMember m) { JacksonInject ann = m.getAnnotation(JacksonInject.class); if (ann == null) { return null; } /* Empty String means that we should use name of declared * value class. */ String id = ann.value(); if (id.length() == 0) { // slight complication; for setters, type if (!(m instanceof AnnotatedMethod)) { return m.getRawType().getName(); } AnnotatedMethod am = (AnnotatedMethod) m; if (am.getParameterCount() == 0) { return m.getRawType().getName(); } return am.getParameterClass(0).getName(); } return id; }
continue; Class<?> type = accessor.getRawType(); Boolean result = ignores.get(type); if (result == null) {
protected final Class<?> getDeclaringClass() { return getMember().getDeclaringClass(); }
/** * Method that will find if bean has any managed- or back-reference properties, * and if so add them to bean, to be linked during resolution phase. * * @since 1.6 */ protected void addReferenceProperties(DeserializationConfig config, BasicBeanDescription beanDesc, BeanDeserializerBuilder builder) throws JsonMappingException { // and then back references, not necessarily found as regular properties Map<String,AnnotatedMember> refs = beanDesc.findBackReferenceProperties(); if (refs != null) { for (Map.Entry<String, AnnotatedMember> en : refs.entrySet()) { String name = en.getKey(); AnnotatedMember m = en.getValue(); if (m instanceof AnnotatedMethod) { builder.addBackReferenceProperty(name, constructSettableProperty( config, beanDesc, m.getName(), (AnnotatedMethod) m)); } else { builder.addBackReferenceProperty(name, constructSettableProperty( config, beanDesc, m.getName(), (AnnotatedField) m)); } } } }
private AnnotationMap _mergeAnnotations(int index, Node<? extends AnnotatedMember>... nodes) { AnnotationMap ann = nodes[index].value.getAllAnnotations(); ++index; for (; index < nodes.length; ++index) { if (nodes[index] != null) { return AnnotationMap.merge(ann, _mergeAnnotations(index, nodes)); } } return ann; }
public void inject(DeserializationContext context, Object beanInstance) throws IOException { _member.setValue(beanInstance, findValue(context, beanInstance)); } }
@Override public Object findInjectableValueId(AnnotatedMember m) { JacksonInject ann = m.getAnnotation(JacksonInject.class); if (ann == null) { return null; } /* Empty String means that we should use name of declared * value class. */ String id = ann.value(); if (id.length() == 0) { // slight complication; for setters, type if (!(m instanceof AnnotatedMethod)) { return m.getRawType().getName(); } AnnotatedMethod am = (AnnotatedMethod) m; if (am.getParameterCount() == 0) { return m.getRawType().getName(); } return am.getParameterClass(0).getName(); } return id; }
Class<?> rawBase = property.getRawType(); for (NamedType subtype : _registeredSubtypes) { NamedType rootType = new NamedType(property.getRawType(), null); AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(property.getRawType(), ai, config);
protected final Class<?> getDeclaringClass() { return getMember().getDeclaringClass(); }
/** * Method that will find if bean has any managed- or back-reference properties, * and if so add them to bean, to be linked during resolution phase. * * @since 1.6 */ protected void addReferenceProperties(DeserializationConfig config, BasicBeanDescription beanDesc, BeanDeserializerBuilder builder) throws JsonMappingException { // and then back references, not necessarily found as regular properties Map<String,AnnotatedMember> refs = beanDesc.findBackReferenceProperties(); if (refs != null) { for (Map.Entry<String, AnnotatedMember> en : refs.entrySet()) { String name = en.getKey(); AnnotatedMember m = en.getValue(); if (m instanceof AnnotatedMethod) { builder.addBackReferenceProperty(name, constructSettableProperty( config, beanDesc, m.getName(), (AnnotatedMethod) m)); } else { builder.addBackReferenceProperty(name, constructSettableProperty( config, beanDesc, m.getName(), (AnnotatedField) m)); } } } }
private AnnotationMap _mergeAnnotations(int index, Node<? extends AnnotatedMember>... nodes) { AnnotationMap ann = nodes[index].value.getAllAnnotations(); ++index; for (; index < nodes.length; ++index) { if (nodes[index] != null) { return AnnotationMap.merge(ann, _mergeAnnotations(index, nodes)); } } return ann; }
public void inject(DeserializationContext context, Object beanInstance) throws IOException { _member.setValue(beanInstance, findValue(context, beanInstance)); } }
/** * Method called locate all members used for value injection (if any), * constructor {@link org.codehaus.jackson.map.deser.impl.ValueInjector} instances, and add them to builder. * * @since 1.9 */ protected void addInjectables(DeserializationConfig config, BasicBeanDescription beanDesc, BeanDeserializerBuilder builder) throws JsonMappingException { Map<Object, AnnotatedMember> raw = beanDesc.findInjectables(); if (raw != null) { boolean fixAccess = config.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS); for (Map.Entry<Object, AnnotatedMember> entry : raw.entrySet()) { AnnotatedMember m = entry.getValue(); if (fixAccess) { m.fixAccess(); // to ensure we can call it } builder.addInjectable(m.getName(), beanDesc.resolveType(m.getGenericType()), beanDesc.getClassAnnotations(), m, entry.getKey()); } } }
/** * Secondary helper method for constructing {@link BeanPropertyWriter} for * given member (field or method). */ protected BeanPropertyWriter _constructWriter(SerializationConfig config, TypeBindings typeContext, PropertyBuilder pb, boolean staticTyping, String name, AnnotatedMember accessor) throws JsonMappingException { if (config.isEnabled(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) { accessor.fixAccess(); } JavaType type = accessor.getType(typeContext); BeanProperty.Std property = new BeanProperty.Std(name, type, pb.getClassAnnotations(), accessor); // Does member specify a serializer? If so, let's use it. JsonSerializer<Object> annotatedSerializer = findSerializerFromAnnotation(config, accessor, property); // And how about polymorphic typing? First special to cover JAXB per-field settings: TypeSerializer contentTypeSer = null; if (ClassUtil.isCollectionMapOrArray(type.getRawClass())) { contentTypeSer = findPropertyContentTypeSerializer(type, config, accessor, property); } // and if not JAXB collection/array with annotations, maybe regular type info? TypeSerializer typeSer = findPropertyTypeSerializer(type, config, accessor, property); BeanPropertyWriter pbw = pb.buildWriter(name, type, annotatedSerializer, typeSer, contentTypeSer, accessor, staticTyping); // how about views? (1.4+) AnnotationIntrospector intr = config.getAnnotationIntrospector(); pbw.setViews(intr.findSerializationViews(accessor)); return pbw; }
@Override public <A extends Annotation> A getAnnotation(Class<A> acls) { return _member.getAnnotation(acls); }