Search in sources :

Example 1 with JsonAlias

use of com.fasterxml.jackson.annotation.JsonAlias in project ddf-common by dongfangding.

the class JacksonAnnotationIntrospector method findPropertyAliases.

@Override
public List<PropertyName> findPropertyAliases(Annotated m) {
    JsonAlias ann = _findAnnotation(m, JsonAlias.class);
    if (ann == null) {
        return null;
    }
    String[] strs = ann.value();
    final int len = strs.length;
    if (len == 0) {
        return Collections.emptyList();
    }
    List<PropertyName> result = new ArrayList<>(len);
    for (int i = 0; i < len; ++i) {
        result.add(PropertyName.construct(strs[i]));
    }
    return result;
}
Also used : PropertyName(com.fasterxml.jackson.databind.PropertyName) JsonAlias(com.fasterxml.jackson.annotation.JsonAlias) ArrayList(java.util.ArrayList)

Example 2 with JsonAlias

use of com.fasterxml.jackson.annotation.JsonAlias in project DJI-Cloud-API-Demo by dji-sdk.

the class CustomClaim method convertToMap.

/**
 * Convert the custom claim data type to the Map type.
 * @return map
 */
public ConcurrentHashMap<String, String> convertToMap() {
    ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>(4);
    try {
        Field[] declaredFields = this.getClass().getDeclaredFields();
        for (Field field : declaredFields) {
            JsonAlias annotation = field.getAnnotation(JsonAlias.class);
            field.setAccessible(true);
            // The value of key is named underscore.
            map.put(annotation != null ? annotation.value()[0] : field.getName(), field.get(this).toString());
        }
    } catch (IllegalAccessException e) {
        log.info("CustomClaim converts failed. {}", this.toString());
        e.printStackTrace();
    }
    return map;
}
Also used : Field(java.lang.reflect.Field) JsonAlias(com.fasterxml.jackson.annotation.JsonAlias) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

JsonAlias (com.fasterxml.jackson.annotation.JsonAlias)2 PropertyName (com.fasterxml.jackson.databind.PropertyName)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1