Package org.codehaus.jackson.map.introspect

Examples of org.codehaus.jackson.map.introspect.AnnotatedMethod


        }

        /* [JACKSON-80]: Should support @JsonValue, which is alternative to
         *   actual bean method introspection.
         */
        AnnotatedMethod valueMethod = beanDesc.findJsonValue();
        if (valueMethod != null) {
            /* Further, method itself may also be annotated to indicate
             * exact JsonSerializer to use for whatever value is returned...
             */
            ser = findSerializerFromAnnotation(valueMethod);
            return new JsonValueSerializer(valueMethod.getAnnotated(), ser);
        }

        // First: what properties are to be serializable?
        Collection<BeanPropertyWriter> props = findBeanProperties(config, beanDesc);
        if (props == null || props.size() == 0) {
View Full Code Here


        boolean writeNulls = beanDesc.willWriteNullProperties(config.isEnabled(SerializationConfig.Feature.WRITE_NULL_PROPERTIES));
        boolean fixAccess = config.isEnabled(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS);

        ArrayList<BeanPropertyWriter> props = new ArrayList<BeanPropertyWriter>(methodsByProp.size());
        for (Map.Entry<String,AnnotatedMethod> en : methodsByProp.entrySet()) {
            AnnotatedMethod am = en.getValue();
            if (fixAccess) {
                am.fixAccess();
            }
            /* One more thing: does Method specify a serializer?
             * If so, let's use it.
             */
            JsonSerializer<Object> ser = findSerializerFromAnnotation(am);
            Method m = am.getAnnotated();
            // and finally, there may be per-method overrides:
            boolean methodNulls = am.willWriteNullProperties(writeNulls);
            props.add(new BeanPropertyWriter(en.getKey(), m, ser, methodNulls));
        }
        return props;
    }
View Full Code Here

        /* But then let's decorate things a bit
         */
        /* To resolve [JACKSON-95], need to add "initCause" as setter
         * for exceptions (sub-classes of Throwable).
         */
        AnnotatedMethod am = beanDesc.findMethod("initCause", INIT_CAUSE_PARAMS);
        if (am != null) { // should never be null
            SettableBeanProperty prop = constructSettableProperty(config, "cause", am);
            if (prop != null) {
                deser.addProperty(prop);
            }
View Full Code Here

    {
        boolean autodetect = config.isEnabled(DeserializationConfig.Feature.AUTO_DETECT_SETTERS);
        Map<String,AnnotatedMethod> setters = beanDesc.findSetters(autodetect);
        // Also, do we have a fallback "any" setter? If so, need to bind
        {
            AnnotatedMethod anyM = beanDesc.findAnySetter();
            if (anyM != null) {
                deser.setAnySetter(constructAnySetter(config, anyM));
            }
        }

        /* No setters? Should we proceed here? It may well be ok, if
         * there are factory methods or such.
         */
        //if (setters.isEmpty() && anySetter == null) ...

        // These are all valid setters, but we do need to introspect bit more
        for (Map.Entry<String,AnnotatedMethod> en : setters.entrySet()) {
            AnnotatedMethod setter = en.getValue();
            SettableBeanProperty prop = constructSettableProperty(config, en.getKey(), setter);
            if (prop != null) {
                deser.addProperty(prop);
            }
        }

        /* As per [JACKSON-88], may also need to consider getters
         * for Map/Collection properties
         */
        if (config.isEnabled(DeserializationConfig.Feature.USE_GETTERS_AS_SETTERS)) {
            /* Hmmh. We have to assume that 'use getters as setters' also
             * implies 'yes, do auto-detect these getters'? (if not, we'd
             * need to add AUTO_DETECT_GETTERS to deser config too, not
             * just ser config)
             */
            Map<String,AnnotatedMethod> getters = beanDesc.findGetters(true, setters.keySet());
            for (Map.Entry<String,AnnotatedMethod> en : getters.entrySet()) {
                AnnotatedMethod getter = en.getValue();
                // should only consider Collections and Maps, for now?
                Class<?> rt = getter.getReturnType();
                if (Collection.class.isAssignableFrom(rt)
                    || Map.class.isAssignableFrom(rt)) {
                    deser.addProperty(constructSetterlessProperty(config, en.getKey(), getter));
                }
            }
View Full Code Here

        AnnotatedClass ac = AnnotatedClass.constructFull
            (NumberBean.class, JacksonAnnotationFilter.instance, true, BasicClassIntrospector.SetterMethodFilter.instance);
        Collection<AnnotatedMethod> methods = ac.getMemberMethods();
        assertEquals(1, methods.size());

        AnnotatedMethod am = methods.iterator().next();

        assertEquals("setX", am.getName());
        // should be one from sub-class
        assertEquals(NumberBean.class, am.getDeclaringClass());
        Type[] types = am.getGenericParameterTypes();
        assertEquals(Integer.class, types[0]);
    }
View Full Code Here

        AnnotatedClass ac = AnnotatedClass.construct(NumberBean.class, new JacksonAnnotationIntrospector(), null);
        ac.resolveMemberMethods(BasicClassIntrospector.DEFAULT_SETTER_FILTER);
        assertEquals(1, ac.getMemberMethodCount());

        Iterator<AnnotatedMethod> it = ac.memberMethods().iterator();
        AnnotatedMethod am = it.next();

        assertEquals("setX", am.getName());
        // should be one from sub-class
        assertEquals(NumberBean.class, am.getDeclaringClass());
        assertEquals(Integer.class, am.getParameterClass(0));
    }
View Full Code Here

  }

  @Override
  public Object findDeserializer(Annotated a) {
    if (a instanceof AnnotatedMethod) {
      AnnotatedMethod method = (AnnotatedMethod) a;
      TypeDescriptor typeDescriptor = getTypeDescriptorForDeserializer(method);
      for (Annotation ann : typeDescriptor.getAnnotations()){
        if (isHandled(ann)) {
          return new ConvertingDeserializer(this.conversionService, typeDescriptor);
        }
View Full Code Here

  @Override
  public Object findSerializer(Annotated a) {
    // this seems to be called even if the method is not annotated with an actual annotation???
    if (a instanceof AnnotatedMethod) {
      AnnotatedMethod method = (AnnotatedMethod) a;
      TypeDescriptor typeDescriptor = getTypeDescriptorForSerializer(method);
      for (Annotation ann : typeDescriptor.getAnnotations()){
        if (isHandled(ann)) {
          return new ConvertingSerializer(this.conversionService, typeDescriptor);
        }
View Full Code Here

    }
    /* 16-Feb-2010, tatu: May also have annotation associated with field, not method
     *    itself... and findAnnotation() won't find that (nor property descriptor)
     */
    if ((a instanceof AnnotatedMethod) && propName != null) {
      AnnotatedMethod am = (AnnotatedMethod) a;
      annotation = this.findFieldAnnotation(XmlElement.class, am.getDeclaringClass(), propName);
      if (annotation != null && annotation.type() != XmlElement.DEFAULT.class) {
        return annotation.type();
      }
    }
    return null;
View Full Code Here

        AnnotatedClass ac = AnnotatedClass.construct(NumberBean.class, new JacksonAnnotationIntrospector(), null);
        ac.resolveMemberMethods(BasicClassIntrospector.SetterMethodFilter.instance);
        assertEquals(1, ac.getMemberMethodCount());

        Iterator<AnnotatedMethod> it = ac.memberMethods().iterator();
        AnnotatedMethod am = it.next();

        assertEquals("setX", am.getName());
        // should be one from sub-class
        assertEquals(NumberBean.class, am.getDeclaringClass());
        assertEquals(Integer.class, am.getParameterClass(0));
    }
View Full Code Here

TOP

Related Classes of org.codehaus.jackson.map.introspect.AnnotatedMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.