Example usage for com.fasterxml.jackson.databind.introspect AnnotatedMethod getName

List of usage examples for com.fasterxml.jackson.databind.introspect AnnotatedMethod getName

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.introspect AnnotatedMethod getName.

Prototype

public String getName() 

Source Link

Usage

From source file:Main.java

public static String okNameForMutator(AnnotatedMethod am, String prefix) {
    String name = am.getName();
    if (name.startsWith(prefix)) {
        return manglePropertyName(name.substring(prefix.length()));
    }/*from  ww w .  ja  v  a2s  . c o m*/
    return null;
}

From source file:Main.java

public static String okNameForGetter(AnnotatedMethod am) {
    String name = am.getName();
    String str = okNameForIsGetter(am, name);
    if (str == null) {
        str = okNameForRegularGetter(am, name);
    }/*from ww w.  j ava  2  s .  co  m*/
    return str;
}

From source file:io.fabric8.cxf.endpoint.BeanValidationAnnotationIntrospector.java

@Override
public boolean hasIgnoreMarker(AnnotatedMember m) {
    Member member = m.getMember();
    int modifiers = member.getModifiers();
    if (Modifier.isTransient(modifiers)) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Ignoring transient member " + m);
        }/*www .  ja  va 2  s.c  om*/
        return true;
    } else if (m instanceof AnnotatedMethod) {
        AnnotatedMethod method = (AnnotatedMethod) m;
        String methodName = method.getName();
        // lets see if there is a transient field of the same name as the getter
        if (methodName.startsWith("get") && method.getParameterCount() == 0) {
            String fieldName = Introspector.decapitalize(methodName.substring(3));
            Class<?> declaringClass = method.getDeclaringClass();
            Field field = findField(fieldName, declaringClass);
            if (field != null) {
                int fieldModifiers = field.getModifiers();
                if (Modifier.isTransient(fieldModifiers)) {
                    LOG.fine("Ignoring member " + m + " due to transient field called " + fieldName);
                    return true;
                }
            }
        }
    }
    return super.hasIgnoreMarker(m);

}

From source file:io.fabric8.cxf.endpoint.IgnorePropertiesBackedByTransientFields.java

@Override
public boolean isGetterVisible(AnnotatedMethod method) {
    boolean answer = defaultChecker.isGetterVisible(method);
    if (answer) {
        answer = isGetterMethodWithFieldVisible(method, getGetterFieldName(method.getName()),
                method.getDeclaringClass())
                && isGetterMethodRetItselfVisible(method.getMember(), method.getDeclaringClass());
    }/*  w w w.j  av a 2 s  .c  o  m*/
    return answer;
}

From source file:io.fabric8.cxf.endpoint.IgnorePropertiesBackedByTransientFields.java

@Override
public boolean isIsGetterVisible(AnnotatedMethod method) {
    boolean answer = defaultChecker.isIsGetterVisible(method);
    if (answer) {
        answer = isGetterMethodWithFieldVisible(method, getIsGetterFieldName(method.getName()),
                method.getDeclaringClass())
                && isGetterMethodRetItselfVisible(method.getMember(), method.getDeclaringClass());
    }/*from  ww  w . j a  v a 2  s. co m*/
    return answer;
}

From source file:ca.oson.json.Oson.java

public ObjectMapper getJackson() {
    if (jackson == null) {
        jackson = new ObjectMapper();
        prefixProcessing();// www. j a va 2s  .  c  o  m

        // do not fail for funny reason
        jackson.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        jackson.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

        switch (getDefaultType()) {
        case ALWAYS:
            jackson.setSerializationInclusion(Include.ALWAYS);
            break;
        case NON_NULL:
            jackson.setSerializationInclusion(Include.NON_NULL);
            break;
        case NON_EMPTY:
            jackson.setSerializationInclusion(Include.NON_EMPTY);
            break;
        case DEFAULT:
            jackson.setSerializationInclusion(Include.USE_DEFAULTS);
            break;
        default:
            jackson.setSerializationInclusion(Include.NON_NULL);
            break;
        }

        if (getPrettyPrinting() && getIndentation() > 0) {
            jackson.enable(SerializationFeature.INDENT_OUTPUT);
            jackson.configure(SerializationFeature.INDENT_OUTPUT, true);
        }

        if (getOrderByKeyAndProperties()) {
            jackson.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
        }

        Set<FieldMapper> mappers = getFieldMappers();
        if (mappers != null) {
            //defines how names of JSON properties ("external names") are derived from names of POJO methods and fields ("internal names"),
            // in cases where they are not auto-detected and no explicit annotations exist for naming
            // config - Configuration in used: either SerializationConfig or DeserializationConfig,
            // depending on whether method is called during serialization or deserialization
            jackson.setPropertyNamingStrategy(new PropertyNamingStrategy() {
                @Override
                public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) {
                    String name = defaultName;
                    if (name == null) {
                        name = field.getName();
                    }
                    name = name.trim();
                    if (name.isEmpty()) {
                        return super.nameForField(config, field, defaultName);
                    }

                    String lname = name.toLowerCase();

                    if (config instanceof SerializationConfig || !(config instanceof DeserializationConfig)) {
                        for (FieldMapper fieldMapper : mappers) {
                            String java = fieldMapper.java;

                            if (java != null && lname.equals(java.toLowerCase())) {
                                Class<?> type = fieldMapper.getType();
                                String fullName = field.getFullName(); // ca.oson.json.Artist#age;
                                int index = fullName.indexOf('#');
                                if (index > -1) {
                                    fullName = fullName.substring(0, index);
                                }

                                if (type != null) {
                                    try {
                                        // mapper.getType().getTypeName() is the same as mapper.getType().getName()
                                        if (type.getTypeName().equals(fullName)) {
                                            return fieldMapper.json;
                                        }

                                    } catch (SecurityException e) {
                                        // e.printStackTrace();
                                    }

                                } else { // just by name
                                    return fieldMapper.json;
                                }
                            }
                        }

                    }

                    if (config instanceof DeserializationConfig || !(config instanceof SerializationConfig)) {
                        for (FieldMapper fieldMapper : mappers) {
                            String json = fieldMapper.json;

                            if (json != null && lname.equals(json.toLowerCase())) {
                                Class<?> type = fieldMapper.getType();
                                String fullName = field.getFullName(); // ca.oson.json.Artist#age;
                                int index = fullName.indexOf('#');
                                if (index > -1) {
                                    fullName = fullName.substring(0, index);
                                }

                                if (type != null) {
                                    try {
                                        // mapper.getType().getTypeName() is the same as mapper.getType().getName()
                                        if (type.getTypeName().equals(fullName)) {
                                            return fieldMapper.java;
                                        }

                                    } catch (SecurityException e) {
                                        // e.printStackTrace();
                                    }

                                } else { // just by name
                                    return fieldMapper.java;
                                }
                            }
                        }

                    }

                    return super.nameForField(config, field, defaultName);
                }

                @Override
                public String nameForGetterMethod(MapperConfig<?> config, AnnotatedMethod method,
                        String defaultName) {
                    String name = defaultName;
                    if (name == null) {
                        name = method.getName().substring(3);
                    }
                    name = name.trim();
                    if (name.isEmpty()) {
                        return super.nameForGetterMethod(config, method, defaultName);
                    }

                    String lname = name.toLowerCase();

                    if (config instanceof SerializationConfig || !(config instanceof DeserializationConfig)) {
                        for (FieldMapper fieldMapper : mappers) {
                            String java = fieldMapper.java;

                            if (java != null && lname.equals(java.toLowerCase())) {
                                Class<?> type = fieldMapper.getType();
                                String fullName = method.getFullName(); // java.util.Date#getTime(0 params)
                                int index = fullName.indexOf('#');
                                if (index > -1) {
                                    fullName = fullName.substring(0, index);
                                }

                                if (type != null) {
                                    try {
                                        // mapper.getType().getTypeName() is the same as mapper.getType().getName()
                                        if (type.getTypeName().equals(fullName)) {
                                            return fieldMapper.json;
                                        }

                                    } catch (SecurityException e) {
                                        // e.printStackTrace();
                                    }

                                } else { // just by name
                                    return fieldMapper.json;
                                }
                            }
                        }

                    }

                    if (config instanceof DeserializationConfig || !(config instanceof SerializationConfig)) {
                        for (FieldMapper fieldMapper : mappers) {
                            String json = fieldMapper.json;

                            if (json != null && lname.equals(json.toLowerCase())) {
                                Class<?> type = fieldMapper.getType();
                                String fullName = method.getFullName(); // java.util.Date#getTime(0 params)
                                int index = fullName.indexOf('#');
                                if (index > -1) {
                                    fullName = fullName.substring(0, index);
                                }

                                if (type != null) {
                                    try {
                                        // mapper.getType().getTypeName() is the same as mapper.getType().getName()
                                        if (type.getTypeName().equals(fullName)) {
                                            return fieldMapper.java;
                                        }

                                    } catch (SecurityException e) {
                                        // e.printStackTrace();
                                    }

                                } else { // just by name
                                    return fieldMapper.java;
                                }
                            }
                        }

                    }

                    return super.nameForGetterMethod(config, method, defaultName);
                }

                /*
                 * (non-Javadoc)
                 * @see com.fasterxml.jackson.databind.PropertyNamingStrategy#nameForSetterMethod(com.fasterxml.jackson.databind.cfg.MapperConfig, com.fasterxml.jackson.databind.introspect.AnnotatedMethod, java.lang.String)
                 *
                 * Method called to find external name (name used in JSON) for given logical POJO property, as defined by given setter method; typically called when building a deserializer (but not necessarily only then).
                 */
                @Override
                public String nameForSetterMethod(MapperConfig<?> config, AnnotatedMethod method,
                        String defaultName) {
                    String name = defaultName;
                    if (name == null) {
                        name = method.getName().substring(3);
                    }
                    name = name.trim();
                    if (name.isEmpty()) {
                        return super.nameForSetterMethod(config, method, defaultName);
                    }

                    String lname = name.toLowerCase();

                    if (config instanceof SerializationConfig || !(config instanceof DeserializationConfig)) {
                        for (FieldMapper fieldMapper : mappers) {
                            String java = fieldMapper.java;

                            if (java != null && lname.equals(java.toLowerCase())) {
                                Class<?> type = fieldMapper.getType();
                                String fullName = method.getFullName(); // java.util.Date#getTime(0 params)
                                int index = fullName.indexOf('#');
                                if (index > -1) {
                                    fullName = fullName.substring(0, index);
                                }

                                if (type != null) {
                                    try {
                                        // mapper.getType().getTypeName() is the same as mapper.getType().getName()
                                        if (type.getTypeName().equals(fullName)) {
                                            return fieldMapper.json;
                                        }

                                    } catch (SecurityException e) {
                                        // e.printStackTrace();
                                    }

                                } else { // just by name
                                    return fieldMapper.json;
                                }
                            }
                        }

                    }

                    if (config instanceof DeserializationConfig || !(config instanceof SerializationConfig)) {
                        for (FieldMapper fieldMapper : mappers) {
                            String json = fieldMapper.json;

                            if (json != null && lname.equals(json.toLowerCase())) {
                                Class<?> type = fieldMapper.getType();
                                String fullName = method.getFullName(); // java.util.Date#getTime(0 params)
                                int index = fullName.indexOf('#');
                                if (index > -1) {
                                    fullName = fullName.substring(0, index);
                                }

                                if (type != null) {
                                    try {
                                        // mapper.getType().getTypeName() is the same as mapper.getType().getName()
                                        if (type.getTypeName().equals(fullName)) {
                                            return fieldMapper.java;
                                        }

                                    } catch (SecurityException e) {
                                        // e.printStackTrace();
                                    }

                                } else { // just by name
                                    return fieldMapper.java;
                                }
                            }
                        }

                    }

                    return super.nameForSetterMethod(config, method, defaultName);
                }

                /*
                 * (non-Javadoc)
                 * @see com.fasterxml.jackson.databind.PropertyNamingStrategy#nameForConstructorParameter(com.fasterxml.jackson.databind.cfg.MapperConfig, com.fasterxml.jackson.databind.introspect.AnnotatedParameter, java.lang.String)
                 *
                 * find external name (name used in JSON) for given logical POJO property, as defined by given setter method; typically called when building a deserializer (but not necessarily only then).
                 */
                @Override
                public String nameForConstructorParameter(MapperConfig<?> config, AnnotatedParameter ctorParam,
                        String defaultName) {
                    String name = defaultName;
                    if (name == null) {
                        name = ctorParam.getName();
                    }
                    name = name.trim();
                    if (name.isEmpty()) {
                        return super.nameForConstructorParameter(config, ctorParam, defaultName);
                    }

                    String lname = name.toLowerCase();

                    if (config instanceof SerializationConfig || !(config instanceof DeserializationConfig)) {
                        for (FieldMapper fieldMapper : mappers) {
                            String java = fieldMapper.java;

                            if (java != null && lname.equals(java.toLowerCase())) {
                                Class<?> type = fieldMapper.getType();
                                String fullName = ctorParam.getName(); // java.util.Date#
                                int index = fullName.indexOf('#');
                                if (index > -1) {
                                    fullName = fullName.substring(0, index);
                                }

                                if (type != null) {
                                    try {
                                        // mapper.getType().getTypeName() is the same as mapper.getType().getName()
                                        if (type.getTypeName().equals(fullName)) {
                                            return fieldMapper.json;
                                        }

                                    } catch (SecurityException e) {
                                        // e.printStackTrace();
                                    }

                                } else { // just by name
                                    String json = fieldMapper.json;

                                    if (json == null) {
                                        // do nothing?

                                    } else {
                                        return json;
                                    }
                                }
                            }
                        }

                    }

                    if (config instanceof DeserializationConfig || !(config instanceof SerializationConfig)) {
                        for (FieldMapper fieldMapper : mappers) {
                            String json = fieldMapper.json;

                            if (json != null && lname.equals(json.toLowerCase())) {
                                Class<?> type = fieldMapper.getType();
                                String fullName = ctorParam.getName(); // java.util.Date#
                                int index = fullName.indexOf('#');
                                if (index > -1) {
                                    fullName = fullName.substring(0, index);
                                }

                                if (type != null) {
                                    try {
                                        // mapper.getType().getTypeName() is the same as mapper.getType().getName()
                                        if (type.getTypeName().equals(fullName)) {
                                            return fieldMapper.java;
                                        }

                                    } catch (SecurityException e) {
                                        // e.printStackTrace();
                                    }

                                } else { // just by name
                                    return fieldMapper.java;
                                }
                            }
                        }

                    }

                    return super.nameForConstructorParameter(config, ctorParam, defaultName);
                }

            });
        }

        jackson.setDateFormat(getDateFormat());
    }

    return jackson;
}