Search in sources :

Example 26 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project raml-for-jax-rs by mulesoft-labs.

the class SimpleJacksonClassParser method forFields.

private void forFields(Class<?> classToParse, Map<String, PojoToRamlProperty> propertyMap) {
    for (final Field field : classToParse.getDeclaredFields()) {
        JsonProperty elem = field.getAnnotation(JsonProperty.class);
        if (elem != null) {
            final String name = elem.value().equals("") ? field.getName() : elem.value();
            propertyMap.put(name, new PojoToRamlProperty() {

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

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

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

Example 27 with JsonProperty

use of 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 28 with JsonProperty

use of 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 29 with JsonProperty

use of 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 30 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityDetailsDto method getCharacteristics.

@JsonProperty("characteristics")
@JsonView({ CommonView.class })
public Map<String, Set<Object>> getCharacteristics() {
    Map<String, Set<Object>> characMap = null;
    if (fluxCharacteristics != null) {
        characMap = Maps.newHashMap();
        for (FluxCharacteristicsDto fluxCharacteristicsDto : fluxCharacteristics) {
            Double calculatedValueMeasure = fluxCharacteristicsDto.getCalculatedValueMeasure();
            add("calculatedValueMeasure", calculatedValueMeasure, characMap);
            Double calculatedValueQuantity = fluxCharacteristicsDto.getCalculatedValueQuantity();
            add("calculatedValueQuantity", calculatedValueQuantity, characMap);
            String description = fluxCharacteristicsDto.getDescription();
            add("description", description, characMap);
            String descriptionLanguageId = fluxCharacteristicsDto.getDescriptionLanguageId();
            add("descriptionLanguageId", descriptionLanguageId, characMap);
            String typeCode = fluxCharacteristicsDto.getTypeCode();
            add("typeCode", typeCode, characMap);
            String typeCodeListId = fluxCharacteristicsDto.getTypeCodeListId();
            add("typeCodeListId", typeCodeListId, characMap);
            Date valueDateTime = fluxCharacteristicsDto.getValueDateTime();
            add("valueDateTime", valueDateTime, characMap);
            String valueIndicator = fluxCharacteristicsDto.getValueIndicator();
            add("valueIndicator", valueIndicator, characMap);
            Double valueMeasure = fluxCharacteristicsDto.getValueMeasure();
            add("valueMeasure", valueMeasure, characMap);
            String valueMeasureUnitCode = fluxCharacteristicsDto.getValueMeasureUnitCode();
            add("valueMeasureUnitCode", valueMeasureUnitCode, characMap);
            Double valueQuantity = fluxCharacteristicsDto.getValueQuantity();
            add("valueQuantity", valueQuantity, characMap);
            String valueQuantityCode = fluxCharacteristicsDto.getValueQuantityCode();
            add("valueQuantityCode", valueQuantityCode, characMap);
            String valueLanguageId = fluxCharacteristicsDto.getValueLanguageId();
            add("valueLanguageId", valueLanguageId, characMap);
            String valueCode = fluxCharacteristicsDto.getValueCode();
            add("valueCode", valueCode, characMap);
        }
    }
    return characMap;
}
Also used : Set(java.util.Set) ToString(lombok.ToString) FluxCharacteristicsDto(eu.europa.ec.fisheries.ers.service.dto.FluxCharacteristicsDto) Date(java.util.Date) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) JsonView(com.fasterxml.jackson.annotation.JsonView)

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