Search in sources :

Example 36 with JsonProperty

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

the class PreferenceStore method setEntries.

@JsonProperty("entries")
public void setEntries(JsonNode entries) {
    Iterator<String> i = entries.fieldNames();
    while (i.hasNext()) {
        String key = i.next();
        if (entries.get(key) != null) {
            JsonNode o = entries.get(key);
            Object loaded = loadObject(o);
            if (loaded == null) {
                if ("scripting.starred-expressions".contentEquals(key)) {
                    // HACK to work around preferences corruption
                    loaded = new TopList(10);
                }
            }
            _prefs.put(key, loaded);
        }
    }
    // internal puts don't count
    dirty = false;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty)

Example 37 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project textdb by TextDB.

the class JsonSchemaHelper method getPropertyDefaultValues.

public static Map<String, Object> getPropertyDefaultValues(Class<? extends PredicateBase> predicateClass) {
    HashMap<String, Object> defaultValueMap = new HashMap<>();
    Constructor<?> constructor = getJsonCreatorConstructor(predicateClass);
    // get all parameter types
    Class<?>[] parameterTypes = constructor.getParameterTypes();
    for (int i = 0; i < parameterTypes.length; i++) {
        // find the @JsonProperty annotation for each parameter
        Annotation[] annotations = constructor.getParameterAnnotations()[i];
        Optional<Annotation> findJsonProperty = Arrays.asList(annotations).stream().filter(annotation -> annotation.annotationType().equals(JsonProperty.class)).findAny();
        if (!findJsonProperty.isPresent()) {
            continue;
        }
        // convert the defaultValue from the string to the parameter's type
        JsonProperty jsonProperty = (JsonProperty) findJsonProperty.get();
        if (!jsonProperty.defaultValue().trim().isEmpty()) {
            defaultValueMap.put(jsonProperty.value(), objectMapper.convertValue(jsonProperty.defaultValue(), parameterTypes[i]));
        }
    }
    return defaultValueMap;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) java.util(java.util) OperatorArityConstants(edu.uci.ics.texera.dataflow.plangen.OperatorArityConstants) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonSchema(com.fasterxml.jackson.module.jsonSchema.JsonSchema) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) Constructor(java.lang.reflect.Constructor) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) Utils(edu.uci.ics.texera.api.utils.Utils) JsonSchemaGenerator(com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator) Annotation(java.lang.annotation.Annotation) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) AdvancedOption(edu.uci.ics.texera.dataflow.annotation.AdvancedOption) JsonNode(com.fasterxml.jackson.databind.JsonNode) DataConstants(edu.uci.ics.texera.api.constants.DataConstants) Path(java.nio.file.Path) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Annotation(java.lang.annotation.Annotation) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass)

Example 38 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project textdb by TextDB.

the class JsonSchemaHelper method getRequiredProperties.

public static List<String> getRequiredProperties(Class<? extends PredicateBase> predicateClass) {
    ArrayList<String> requiredProperties = new ArrayList<>();
    Constructor<?> constructor = getJsonCreatorConstructor(predicateClass);
    for (Annotation[] annotations : Arrays.asList(constructor.getParameterAnnotations())) {
        // find the @JsonProperty annotation for each parameter
        Optional<Annotation> findJsonProperty = Arrays.asList(annotations).stream().filter(annotation -> annotation.annotationType().equals(JsonProperty.class)).findAny();
        if (!findJsonProperty.isPresent()) {
            continue;
        }
        // add the required property to the list
        JsonProperty jsonProperty = (JsonProperty) findJsonProperty.get();
        if (jsonProperty.required()) {
            requiredProperties.add(jsonProperty.value());
        }
    }
    return requiredProperties;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) java.util(java.util) OperatorArityConstants(edu.uci.ics.texera.dataflow.plangen.OperatorArityConstants) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonSchema(com.fasterxml.jackson.module.jsonSchema.JsonSchema) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) Constructor(java.lang.reflect.Constructor) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) Utils(edu.uci.ics.texera.api.utils.Utils) JsonSchemaGenerator(com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator) Annotation(java.lang.annotation.Annotation) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) AdvancedOption(edu.uci.ics.texera.dataflow.annotation.AdvancedOption) JsonNode(com.fasterxml.jackson.databind.JsonNode) DataConstants(edu.uci.ics.texera.api.constants.DataConstants) Path(java.nio.file.Path) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Annotation(java.lang.annotation.Annotation)

Example 39 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project hippo by NHS-digital-website.

the class Checklist method getListentriesJson.

@JsonProperty("listentries")
public List<String> getListentriesJson() {
    List<HippoHtml> entries = getChildBeansByName("website:listentries", HippoHtml.class);
    List<String> entriesStrings = new ArrayList<>();
    for (HippoHtml entry : entries) {
        if (entry != null) {
            entriesStrings.add(entry.getContent());
        } else {
            entriesStrings.add((String) null);
        }
    }
    return entriesStrings;
}
Also used : HippoHtml(org.hippoecm.hst.content.beans.standard.HippoHtml) ArrayList(java.util.ArrayList) 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