Search in sources :

Example 1 with PropertyName

use of com.fasterxml.jackson.databind.PropertyName in project jackson-databind by FasterXML.

the class BeanPropertyMap method _buildAliasMapping.

// @since 2.9
private Map<String, String> _buildAliasMapping(Map<String, List<PropertyName>> defs) {
    if ((defs == null) || defs.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<String, String> aliases = new HashMap<>();
    for (Map.Entry<String, List<PropertyName>> entry : defs.entrySet()) {
        String key = entry.getKey();
        if (_caseInsensitive) {
            key = key.toLowerCase();
        }
        for (PropertyName pn : entry.getValue()) {
            String mapped = pn.getSimpleName();
            if (_caseInsensitive) {
                mapped = mapped.toLowerCase();
            }
            aliases.put(mapped, key);
        }
    }
    return aliases;
}
Also used : PropertyName(com.fasterxml.jackson.databind.PropertyName)

Example 2 with PropertyName

use of com.fasterxml.jackson.databind.PropertyName in project jackson-databind by FasterXML.

the class ConcreteBeanPropertyBase method findAliases.

@Override
public List<PropertyName> findAliases(MapperConfig<?> config) {
    List<PropertyName> aliases = _aliases;
    if (aliases == null) {
        AnnotationIntrospector intr = config.getAnnotationIntrospector();
        if (intr != null) {
            aliases = intr.findPropertyAliases(getMember());
        }
        if (aliases == null) {
            aliases = Collections.emptyList();
        }
        _aliases = aliases;
    }
    return aliases;
}
Also used : PropertyName(com.fasterxml.jackson.databind.PropertyName) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector)

Example 3 with PropertyName

use of com.fasterxml.jackson.databind.PropertyName in project jackson-module-afterburner by FasterXML.

the class TestAccessorGeneration method testLotsaIntAccessorGeneration.

// And then test to ensure Switch-table construction also works...
public void testLotsaIntAccessorGeneration() throws Exception {
    PropertyAccessorCollector coll = new PropertyAccessorCollector(BeanN.class);
    String[] methodNames = new String[] { "getX", "getY", "get3", "get4", "get5", "get6", "get7" };
    for (String methodName : methodNames) {
        Method method = BeanN.class.getDeclaredMethod(methodName);
        AnnotatedMethod annMethod = new AnnotatedMethod(null, method, null, null);
        coll.addIntGetter(new BeanPropertyWriter(SimpleBeanPropertyDefinition.construct(null, annMethod, new PropertyName(methodName)), annMethod, null, null, null, null, null, false, null));
    }
    BeanPropertyAccessor acc = coll.findAccessor(null);
    BeanN bean = new BeanN();
    assertEquals(bean.getX(), acc.intGetter(bean, 0));
    assertEquals(bean.getY(), acc.intGetter(bean, 1));
    assertEquals(bean.get3(), acc.intGetter(bean, 2));
    assertEquals(bean.get4(), acc.intGetter(bean, 3));
    assertEquals(bean.get5(), acc.intGetter(bean, 4));
    assertEquals(bean.get6(), acc.intGetter(bean, 5));
    assertEquals(bean.get7(), acc.intGetter(bean, 6));
}
Also used : PropertyName(com.fasterxml.jackson.databind.PropertyName) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) Method(java.lang.reflect.Method) BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter)

Example 4 with PropertyName

use of com.fasterxml.jackson.databind.PropertyName in project requery by requery.

the class EntityAnnotationIntrospector method findObjectIdInfo.

@Override
public ObjectIdInfo findObjectIdInfo(Annotated annotated) {
    Class<?> rawClass = annotated.getType().getRawClass();
    for (Type<?> type : model.getTypes()) {
        if (type.getClassType() == rawClass && type.getSingleKeyAttribute() != null) {
            Attribute<?, ?> attribute = type.getSingleKeyAttribute();
            String name = attribute.getPropertyName();
            if (useTableNames) {
                name = attribute.getName();
            }
            // if the name is overridden use that
            Class<?> superClass = rawClass.getSuperclass();
            while (superClass != Object.class && superClass != null) {
                try {
                    Field field = superClass.getDeclaredField(attribute.getPropertyName());
                    JsonProperty jsonProperty = field.getAnnotation(JsonProperty.class);
                    if (jsonProperty != null) {
                        name = jsonProperty.value();
                        break;
                    }
                } catch (NoSuchFieldException ignored) {
                }
                superClass = superClass.getSuperclass();
            }
            return new ObjectIdInfo(new PropertyName(name), rawClass, ObjectIdGenerators.PropertyGenerator.class, EntityStoreResolver.class);
        }
    }
    return super.findObjectIdInfo(annotated);
}
Also used : Field(java.lang.reflect.Field) PropertyName(com.fasterxml.jackson.databind.PropertyName) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ObjectIdGenerators(com.fasterxml.jackson.annotation.ObjectIdGenerators) ObjectIdInfo(com.fasterxml.jackson.databind.introspect.ObjectIdInfo)

Example 5 with PropertyName

use of com.fasterxml.jackson.databind.PropertyName in project jackson-module-afterburner by FasterXML.

the class TestAccessorGeneration method testSingleIntAccessorGeneration.

/*
    /**********************************************************************
    /* Test methods
    /**********************************************************************
     */
public void testSingleIntAccessorGeneration() throws Exception {
    Method method = Bean1.class.getDeclaredMethod("getX");
    AnnotatedMethod annMethod = new AnnotatedMethod(null, method, null, null);
    PropertyAccessorCollector coll = new PropertyAccessorCollector(Bean1.class);
    BeanPropertyWriter bpw = new BeanPropertyWriter(SimpleBeanPropertyDefinition.construct(null, annMethod, new PropertyName("x")), annMethod, null, null, null, null, null, false, null);
    coll.addIntGetter(bpw);
    BeanPropertyAccessor acc = coll.findAccessor(null);
    Bean1 bean = new Bean1();
    int value = acc.intGetter(bean, 0);
    assertEquals(bean.getX(), value);
}
Also used : PropertyName(com.fasterxml.jackson.databind.PropertyName) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) Method(java.lang.reflect.Method) BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter)

Aggregations

PropertyName (com.fasterxml.jackson.databind.PropertyName)6 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)3 BeanPropertyWriter (com.fasterxml.jackson.databind.ser.BeanPropertyWriter)3 Method (java.lang.reflect.Method)3 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 ObjectIdGenerators (com.fasterxml.jackson.annotation.ObjectIdGenerators)1 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)1 ObjectIdInfo (com.fasterxml.jackson.databind.introspect.ObjectIdInfo)1 Field (java.lang.reflect.Field)1