Search in sources :

Example 31 with JsonProperty

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty in project raml-for-jax-rs by mulesoft-labs.

the class SimpleJacksonClassParser method forProperties.

private void forProperties(Class<?> classToParse, Map<String, PojoToRamlProperty> propertyMap) {
    for (final Method method : classToParse.getDeclaredMethods()) {
        if (!(method.getName().startsWith("get") || method.getName().startsWith("is"))) {
            continue;
        }
        if (Modifier.isStatic(method.getModifiers())) {
            continue;
        }
        JsonProperty elem = method.getAnnotation(JsonProperty.class);
        if (elem != null) {
            final String name = elem.value().equals("") ? buildName(method) : elem.value();
            propertyMap.put(name, new PojoToRamlProperty() {

                @Override
                public <T extends Annotation> Optional<T> getAnnotation(Class<T> annotationType) {
                    return Optional.fromNullable(method.getAnnotation(annotationType));
                }

                @Override
                public String name() {
                    return name;
                }

                @Override
                public Type type() {
                    return method.getGenericReturnType();
                }
            });
        }
    }
}
Also used : Type(java.lang.reflect.Type) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Optional(com.google.common.base.Optional) Method(java.lang.reflect.Method)

Example 32 with JsonProperty

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty in project autorest-clientruntime-for-java by Azure.

the class FlatteningSerializer method serializePartial.

private JsonNode serializePartial(Object value) {
    if (value.getClass().isPrimitive() || value.getClass().isEnum() || value instanceof LocalDate || value instanceof DateTime || value instanceof String || value instanceof DateTimeRfc1123 || value instanceof Period) {
        return mapper.valueToTree(value);
    }
    int mod = value.getClass().getModifiers();
    if (Modifier.isFinal(mod) || Modifier.isStatic(mod)) {
        return mapper.valueToTree(value);
    }
    if (value instanceof List<?>) {
        ArrayNode node = new ArrayNode(mapper.getNodeFactory());
        for (Object val : ((List<?>) value)) {
            node.add(serializePartial(val));
        }
        return node;
    }
    if (value instanceof Map<?, ?>) {
        ObjectNode node = new ObjectNode(mapper.getNodeFactory());
        for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
            node.set((String) entry.getKey(), serializePartial(entry.getValue()));
        }
        return node;
    }
    ObjectNode res = new ObjectNode(mapper.getNodeFactory());
    for (Field f : getAllDeclaredFields(value.getClass())) {
        f.setAccessible(true);
        String wireName = f.getName();
        ObjectNode pointer = res;
        JsonProperty property = f.getAnnotation(JsonProperty.class);
        if (property != null && Access.WRITE_ONLY.equals(property.access())) {
            continue;
        }
        if (property != null && !property.value().isEmpty()) {
            wireName = f.getAnnotation(JsonProperty.class).value();
        }
        try {
            Object propValue = f.get(value);
            if (propValue != null) {
                if (value.getClass().isAnnotationPresent(JsonFlatten.class) && wireName.matches(".+[^\\\\]\\..+")) {
                    String[] values = wireName.split("((?<!\\\\))\\.");
                    for (int i = 0; i < values.length; ++i) {
                        values[i] = values[i].replace("\\.", ".");
                        if (i == values.length - 1) {
                            break;
                        }
                        String val = values[i];
                        if (!pointer.has(val)) {
                            ObjectNode child = new ObjectNode(mapper.getNodeFactory());
                            pointer.set(val, child);
                            pointer = child;
                        } else {
                            pointer = (ObjectNode) pointer.get(val);
                        }
                    }
                    wireName = values[values.length - 1];
                }
                pointer.set(wireName, serializePartial(propValue));
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    return res;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Period(org.joda.time.Period) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Field(java.lang.reflect.Field) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Map(java.util.Map)

Example 33 with JsonProperty

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty in project Krill by KorAP.

the class Match method getID.

/**
 * Get match ID (for later retrieval).
 *
 * @see MatchIdentifier
 */
@Override
@JsonProperty("matchID")
public String getID() {
    // Return identifier as given
    if (this.mirrorIdentifier != null) {
        return this.mirrorIdentifier;
    }
    ;
    // Identifier already created
    if (this.identifier != null) {
        return this.identifier;
    }
    ;
    // No, nada, nix
    if (this.localDocID == -1)
        return null;
    MatchIdentifier id = this.getMatchIdentifier();
    // Get prefix string corpus/doc
    if (this.getTextSigle() != null) {
        id.setTextSigle(this.getTextSigle());
    } else // LEGACY
    {
        id.setCorpusID(this.getCorpusID());
        id.setDocID(this.getDocID());
    }
    ;
    return (this.identifier = id.toString());
}
Also used : MatchIdentifier(de.ids_mannheim.korap.response.match.MatchIdentifier) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty)

Example 34 with JsonProperty

use of org.apache.flink.shaded.jackson2.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 35 with JsonProperty

use of org.apache.flink.shaded.jackson2.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)45 Field (java.lang.reflect.Field)12 ArrayList (java.util.ArrayList)10 Annotation (java.lang.annotation.Annotation)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Method (java.lang.reflect.Method)6 Type (java.lang.reflect.Type)6 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)4 JavaType (com.fasterxml.jackson.databind.JavaType)4 AnnotatedClass (com.fasterxml.jackson.databind.introspect.AnnotatedClass)4 JsonSchema (com.fasterxml.jackson.module.jsonSchema.JsonSchema)4 JsonSchemaGenerator (com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator)4 List (java.util.List)4 JsonIdentityInfo (com.fasterxml.jackson.annotation.JsonIdentityInfo)3