Search in sources :

Example 16 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project jirm by agentgt.

the class SqlParameterDefinition method getSqlBeanParametersFromJsonCreatorConstructor.

private static Map<String, SqlParameterDefinition> getSqlBeanParametersFromJsonCreatorConstructor(Constructor<?> c, SqlObjectConfig config) {
    Map<String, SqlParameterDefinition> parameters = new LinkedHashMap<String, SqlParameterDefinition>();
    Annotation[][] aas = c.getParameterAnnotations();
    Class<?>[] pts = c.getParameterTypes();
    if (aas == null || aas.length == 0) {
        return parameters;
    }
    for (int i = 0; i < aas.length; i++) {
        Annotation[] as = aas[i];
        Class<?> parameterType = pts[i];
        for (int j = 0; j < as.length; j++) {
            Annotation a = as[j];
            if (JsonProperty.class.equals(a.annotationType())) {
                JsonProperty p = (JsonProperty) a;
                String value = p.value();
                final SqlParameterDefinition definition = parameterDef(config, c.getDeclaringClass(), value, parameterType, i);
                parameters.put(value, definition);
            }
        }
    }
    return parameters;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Annotation(java.lang.annotation.Annotation) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project OpenRefine by OpenRefine.

the class FileProjectManager method loadProjects.

@JsonProperty("projectIDs")
protected void loadProjects(List<Long> projectIDs) {
    for (Long id : projectIDs) {
        File projectDir = getProjectDir(id);
        ProjectMetadata metadata = ProjectMetadataUtilities.load(projectDir);
        mergeEmptyUserMetadata(metadata);
        _projectsMetadata.put(id, metadata);
        if (metadata != null && metadata.getTags() != null) {
            for (String tag : metadata.getTags()) {
                if (_projectsTags.containsKey(tag)) {
                    _projectsTags.put(tag, _projectsTags.get(tag) + 1);
                } else {
                    _projectsTags.put(tag, 1);
                }
            }
        }
    }
}
Also used : ProjectMetadata(com.google.refine.ProjectMetadata) File(java.io.File) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty)

Example 18 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project dhis2-core by dhis2.

the class ImportReport method getStats.

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Stats getStats() {
    Stats stats = new Stats();
    typeReportMap.values().forEach(typeReport -> stats.merge(typeReport.getStats()));
    return stats;
}
Also used : Stats(org.hisp.dhis.feedback.Stats) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) JacksonXmlProperty(com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty)

Example 19 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project dhis2-core by dhis2.

the class JacksonPropertyIntrospector method collectProperties.

private static List<Property> collectProperties(Class<?> klass) {
    boolean isPrimitiveOrWrapped = ClassUtils.isPrimitiveOrWrapper(klass);
    if (isPrimitiveOrWrapped) {
        return Collections.emptyList();
    }
    List<Field> fields = ReflectionUtils.findFields(klass, f -> f.isAnnotationPresent(JsonProperty.class));
    List<Method> methods = ReflectionUtils.findMethods(klass, m -> AnnotationUtils.findAnnotation(m, JsonProperty.class) != null && m.getParameterTypes().length == 0);
    Multimap<String, Method> multimap = ReflectionUtils.getMethodsMultimap(klass);
    Map<String, Property> propertyMap = new HashMap<>();
    for (var field : fields) {
        Property property = new Property(klass, null, null);
        property.setAnnotations(getAnnotations(field.getAnnotations()));
        JsonProperty jsonProperty = field.getAnnotation(JsonProperty.class);
        String fieldName = field.getName();
        String name = StringUtils.isEmpty(requireNonNull(jsonProperty).value()) ? fieldName : jsonProperty.value();
        property.setName(name);
        property.setFieldName(fieldName);
        property.setSetterMethod(ReflectionUtils.findSetterMethod(fieldName, klass));
        property.setGetterMethod(ReflectionUtils.findGetterMethod(fieldName, klass));
        property.setNamespace(trimToNull(jsonProperty.namespace()));
        propertyMap.put(name, property);
    }
    for (var method : methods) {
        JsonProperty jsonProperty = AnnotationUtils.findAnnotation(method, JsonProperty.class);
        String fieldName = ReflectionUtils.getFieldName(method);
        String name = StringUtils.isEmpty(requireNonNull(jsonProperty).value()) ? fieldName : jsonProperty.value();
        if (propertyMap.containsKey(name)) {
            continue;
        }
        Property property = new Property(klass, method, null);
        property.setAnnotations(getAnnotations(method.getAnnotations()));
        property.setName(name);
        property.setFieldName(fieldName);
        property.setNamespace(trimToNull(jsonProperty.namespace()));
        propertyMap.put(name, property);
        String setterName = "set" + capitalize(fieldName);
        if (multimap.containsKey(setterName)) {
            property.setSetterMethod(multimap.get(setterName).iterator().next());
        }
        propertyMap.put(name, property);
    }
    return new ArrayList<>(propertyMap.values());
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Field(java.lang.reflect.Field) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) JacksonXmlProperty(com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty) Property(org.hisp.dhis.schema.Property)

Example 20 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project POL-POM-5 by PlayOnLinux.

the class LocalisationHelper method fetchParameterName.

private String fetchParameterName(Parameter parameter) {
    final JsonProperty jsonAnnotation = parameter.getAnnotation(JsonProperty.class);
    final ParameterName parameterNameAnnotation = parameter.getAnnotation(ParameterName.class);
    if (parameterNameAnnotation != null) {
        return parameterNameAnnotation.value();
    }
    if (jsonAnnotation != null) {
        return jsonAnnotation.value();
    }
    return parameter.getName();
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty)

Aggregations

JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)39 ArrayList (java.util.ArrayList)10 Field (java.lang.reflect.Field)9 Annotation (java.lang.annotation.Annotation)8 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)6 Method (java.lang.reflect.Method)6 Type (java.lang.reflect.Type)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 HashMap (java.util.HashMap)5 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)4 JavaType (com.fasterxml.jackson.databind.JavaType)4 AnnotatedClass (com.fasterxml.jackson.databind.introspect.AnnotatedClass)4 JsonIdentityInfo (com.fasterxml.jackson.annotation.JsonIdentityInfo)3 JsonIdentityReference (com.fasterxml.jackson.annotation.JsonIdentityReference)3 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)3 PropertyMetadata (com.fasterxml.jackson.databind.PropertyMetadata)3 AnnotatedMember (com.fasterxml.jackson.databind.introspect.AnnotatedMember)3 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)3