com.fasterxml.jackson.databind.PropertyName Java Examples

The following examples show how to use com.fasterxml.jackson.databind.PropertyName. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: lams   Author: lamsfoundation   File: ConcreteBeanPropertyBase.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source Project: lams   Author: lamsfoundation   File: BeanPropertyMap.java    License: GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #3
Source Project: lams   Author: lamsfoundation   File: Java7SupportImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public PropertyName findConstructorName(AnnotatedParameter p)
{
    AnnotatedWithParams ctor = p.getOwner();
    if (ctor != null) {
        ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class);
        if (props != null) {
            String[] names = props.value();
            int ix = p.getIndex();
            if (ix < names.length) {
                return PropertyName.construct(names[ix]);
            }
        }
    }
    return null;
}
 
Example #4
Source Project: jackson-modules-base   Author: FasterXML   File: ParanamerOnJacksonAnnotationIntrospector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(MapperConfig<?> config, Annotated a)
{
    /* 14-Apr-2014, tatu: Important -- we should NOT introspect name here,
     *   since we are not using annotations; instead it needs to be done
     *   in {@link #findParameterSourceName(AnnotatedParameter)}.
     */
    /*
    PropertyName name = super.findNameForDeserialization(a);
    if (name == null) {
        if (a instanceof AnnotatedParameter) {
            String rawName _paranamer.findParameterName((AnnotatedParameter) a);
            if (rawName != null) {
                return new PropertyName(rawName);
            }
        }
    }
    */
    return null;
}
 
Example #5
Source Project: jackson-modules-base   Author: FasterXML   File: TestAccessorGeneration.java    License: Apache License 2.0 6 votes vote down vote up
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(MAPPER_CONFIG, annMethod, new PropertyName("x")),
            annMethod, null,
            null,
            null, null, null,
            false, null, null);
    coll.addIntGetter(bpw);
    BeanPropertyAccessor acc = coll.findAccessor(null);
    Bean1 bean = new Bean1();
    int value = acc.intGetter(bean, 0);
    assertEquals(bean.getX(), value);
}
 
Example #6
Source Project: conjure   Author: palantir   File: KebabCaseEnforcingAnnotationInspector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated annotatedEntity) {
    // This logic relies on the fact that Immutables generates setters annotated with @JsonProperty.
    // It thus becomes obsolete whenever we move away from Immutables and the deserialization target no longer
    // carries those annotations.

    JsonProperty propertyAnnotation = _findAnnotation(annotatedEntity, JsonProperty.class);
    if (propertyAnnotation != null) {
        String jsonFieldName = propertyAnnotation.value();
        Preconditions.checkArgument(
                KEBAB_CASE_PATTERN.matcher(jsonFieldName).matches(),
                "Conjure grammar requires kebab-case field names: %s",
                jsonFieldName);
    }

    if (annotatedEntity instanceof AnnotatedMethod) {
        AnnotatedMethod maybeSetter = (AnnotatedMethod) annotatedEntity;
        if (maybeSetter.getName().startsWith("set")) {
            // As a pre-caution, require that all setters have a JsonProperty annotation.
            Preconditions.checkArgument(
                    _findAnnotation(annotatedEntity, JsonProperty.class) != null,
                    "All setter ({@code set*}) deserialization targets require @JsonProperty annotations: %s",
                    maybeSetter.getName());
        }
    }

    return null; // delegate to the next introspector in an AnnotationIntrospectorPair.
}
 
Example #7
Source Project: elepy   Author: RyanSusana   File: CustomAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<PropertyName> findPropertyAliases(Annotated ann) {
    if (isId(ann)) {
        return List.of(new PropertyName("_id"), new PropertyName("id"), new PropertyName(ann.getName()));
    }
    return super.findPropertyAliases(ann);
}
 
Example #8
Source Project: elepy   Author: RyanSusana   File: CustomAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated a) {
    String rawName = findPropertyName(a);
    if (rawName != null) {
        return new PropertyName(rawName);
    }
    return null;
}
 
Example #9
Source Project: elepy   Author: RyanSusana   File: CustomAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForSerialization(Annotated a) {

    String rawName = findPropertyName(a);
    if (rawName != null) {
        return new PropertyName(rawName);
    }
    return null;

}
 
Example #10
Source Project: aws-xray-sdk-java   Author: aws   File: UnsignedXrayClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated a) {
    if (a.getName().equals("hTTPMethod")) {
        return HTTP_METHOD;
    }
    if (a.getName().equals("uRLPath")) {
        return URL_PATH;
    }
    return super.findNameForDeserialization(a);
}
 
Example #11
Source Project: lams   Author: lamsfoundation   File: ObjectIdInfo.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected ObjectIdInfo(PropertyName prop, Class<?> scope, Class<? extends ObjectIdGenerator<?>> gen,
        boolean alwaysAsId, Class<? extends ObjectIdResolver> resolver)
{
    _propertyName = prop;
    _scope = scope;
    _generator = gen;
    _alwaysAsId = alwaysAsId;
    if (resolver == null) {
        resolver = SimpleObjectIdResolver.class;
    }
    _resolver = resolver;
}
 
Example #12
Source Project: lams   Author: lamsfoundation   File: BeanPropertyMap.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
public BeanPropertyMap(boolean caseInsensitive, Collection<SettableBeanProperty> props,
        Map<String,List<PropertyName>> aliasDefs)
{
    _caseInsensitive = caseInsensitive;
    _propsInOrder = props.toArray(new SettableBeanProperty[props.size()]);
    _aliasDefs = aliasDefs;
    _aliasMapping = _buildAliasMapping(aliasDefs);
    init(props);
}
 
Example #13
Source Project: lams   Author: lamsfoundation   File: CreatorCandidate.java    License: GNU General Public License v2.0 5 votes vote down vote up
public PropertyName paramName(int i) {
    BeanPropertyDefinition propDef = _params[i].propDef;
    if (propDef != null) {
        return propDef.getFullName();
    }
    return null;
}
 
Example #14
Source Project: lams   Author: lamsfoundation   File: CreatorCandidate.java    License: GNU General Public License v2.0 5 votes vote down vote up
public PropertyName explicitParamName(int i) {
    BeanPropertyDefinition propDef = _params[i].propDef;
    if (propDef != null) {
        if (propDef.isExplicitlyNamed()) {
            return propDef.getFullName();
        }
    }
    return null;
}
 
Example #15
Source Project: lams   Author: lamsfoundation   File: CreatorCandidate.java    License: GNU General Public License v2.0 5 votes vote down vote up
public PropertyName findImplicitParamName(int i) {
    String str = _intr.findImplicitPropertyName(_params[i].annotated);
    if (str != null && !str.isEmpty()) {
        return PropertyName.construct(str);
    }
    return null;
}
 
Example #16
Source Project: lams   Author: lamsfoundation   File: CreatorCandidate.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean hasFullName() {
    if (propDef == null) {
        return false;
    }
    PropertyName n = propDef.getFullName();
    return n.hasSimpleName();
}
 
Example #17
Source Project: lams   Author: lamsfoundation   File: InvalidNullException.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static InvalidNullException from(DeserializationContext ctxt,
        PropertyName name, JavaType type)
{
    String msg = String.format("Invalid `null` value encountered for property %s",
            ClassUtil.quotedOr(name, "<UNKNOWN>"));
    InvalidNullException exc = new InvalidNullException(ctxt, msg, name);
    if (type != null) {
        exc.setTargetType(type);
    }
    return exc;
}
 
Example #18
Source Project: endpoints-java   Author: cloudendpoints   File: ApiAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForSerialization(Annotated a) {
  ApiResourceProperty apiName = a.getAnnotation(ApiResourceProperty.class);
  if (apiName != null && apiName.ignored() != AnnotationBoolean.TRUE) {
    return PropertyName.construct(apiName.name());
  }
  return null;
}
 
Example #19
Source Project: jackson-modules-base   Author: FasterXML   File: TestAccessorGeneration.java    License: Apache License 2.0 5 votes vote down vote up
public void testDualIntAccessorGeneration() throws Exception
{
    PropertyAccessorCollector coll = new PropertyAccessorCollector(Bean3.class);

    String[] methodNames = new String[] {
            "getX", "getY", "get3"
    };
    
    /*
public BeanPropertyWriter(BeanPropertyDefinition propDef,
        AnnotatedMember member, Annotations contextAnnotations,
        JavaType declaredType,
        JsonSerializer<Object> ser, TypeSerializer typeSer, JavaType serType,
        boolean suppressNulls, Object suppressableValue)
     */
    
    for (String methodName : methodNames) {
        Method method = Bean3.class.getDeclaredMethod(methodName);
        AnnotatedMethod annMethod = new AnnotatedMethod(null, method, null, null);
        // should we translate from method name to property name?
        coll.addIntGetter(new BeanPropertyWriter(SimpleBeanPropertyDefinition
                .construct(MAPPER_CONFIG, annMethod, new PropertyName(methodName)),
                annMethod, null,
                null,
                null, null, null,
                false, null, null));
    }

    BeanPropertyAccessor acc = coll.findAccessor(null);
    Bean3 bean = new Bean3();

    assertEquals(bean.getX(), acc.intGetter(bean, 0));
    assertEquals(bean.getY(), acc.intGetter(bean, 1));
    assertEquals(bean.get3(), acc.intGetter(bean, 2));
}
 
Example #20
Source Project: jackson-modules-base   Author: FasterXML   File: TestAccessorGeneration.java    License: Apache License 2.0 5 votes vote down vote up
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(
                MAPPER_CONFIG, annMethod, new PropertyName(methodName)),
                annMethod, null,
                null,
                null, null, null,
                false, null, 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));
}
 
Example #21
Source Project: requery   Author: requery   File: EntityAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@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 = removePrefix(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);
}
 
Example #22
Source Project: requery   Author: requery   File: EntityAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated annotated) {
    if (useTableNames) {
        return getMappedName(annotated);
    } else {
        return super.findNameForDeserialization(annotated);
    }
}
 
Example #23
Source Project: requery   Author: requery   File: EntityAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForSerialization(Annotated annotated) {
    if (useTableNames) {
        return getMappedName(annotated);
    } else {
        return super.findNameForSerialization(annotated);
    }
}
 
Example #24
Source Project: requery   Author: requery   File: EntityAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyName getMappedName(Annotated annotated) {
    if (annotated.hasAnnotation(Table.class)) {
        Table table = annotated.getAnnotation(Table.class);
        return new PropertyName(table.name());
    } if (annotated.hasAnnotation(View.class)) {
        View view = annotated.getAnnotation(View.class);
        return new PropertyName(view.name());
    } else if (annotated.hasAnnotation(Column.class)) {
        Column column = annotated.getAnnotation(Column.class);
        return new PropertyName(column.name());
    } else {
        return null;
    }
}
 
Example #25
Source Project: core-ng-project   Author: neowu   File: JSONAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyName propertyName(Annotated annotated) {
    Property element = annotated.getAnnotation(Property.class);
    if (element != null) {
        return new PropertyName(element.name(), null);
    }
    return null;
}
 
Example #26
Source Project: netty-rest   Author: buremba   File: SwaggerJacksonAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForSerialization(Annotated a)
{
    ApiParam model = a.getAnnotation(ApiParam.class);
    if (model != null && !"".equals(model.value())) {
        return new PropertyName(model.value());
    }
    return null;
}
 
Example #27
Source Project: netty-rest   Author: buremba   File: SwaggerJacksonAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated a)
{
    ApiParam model = a.getAnnotation(ApiParam.class);
    if (model != null && !"".equals(model.value())) {
        return new PropertyName(model.value());
    }
    return null;
}
 
Example #28
Source Project: Rosetta   Author: HubSpot   File: RosettaAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForSerialization(Annotated a) {
  PropertyName propertyName = findRosettaPropertyName(a);
  if (propertyName == null) {
    propertyName = super.findNameForSerialization(a);
  }
  return propertyName;
}
 
Example #29
Source Project: Rosetta   Author: HubSpot   File: RosettaAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated a) {
  PropertyName propertyName = findRosettaPropertyName(a);
  if (propertyName == null) {
    propertyName = super.findNameForDeserialization(a);
  }
  return propertyName;
}
 
Example #30
Source Project: Rosetta   Author: HubSpot   File: RosettaAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyName findRosettaPropertyName(Annotated a) {
  RosettaProperty ann = a.getAnnotation(RosettaProperty.class);
  if (ann != null) {
    return ann.value().isEmpty() ? PropertyName.USE_DEFAULT : new PropertyName(ann.value());
  }
  return null;
}