Search in sources :

Example 11 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project Krill by KorAP.

the class Match method getSnippetHTML.

@JsonProperty("snippet")
public String getSnippetHTML() {
    if (!this._processHighlight())
        return null;
    if (this.processed && this.snippetHTML != null)
        return this.snippetHTML;
    if (DEBUG)
        log.trace("Create HTML Snippet");
    StringBuilder sb = new StringBuilder();
    StringBuilder rightContext = new StringBuilder();
    // Remember ids already defined to
    // have joined elements
    HashSet<String> joins = new HashSet<>(100);
    // Snippet stack sizes
    short start = (short) 0;
    short end = this.snippetArray.size();
    // Create context
    sb.append("<span class=\"context-left\">");
    if (this.startMore)
        sb.append("<span class=\"more\"></span>");
    // Set levels for highlights
    FixedBitSet level = new FixedBitSet(255);
    level.set(0, 255);
    byte[] levelCache = new byte[255];
    HighlightCombinatorElement elem;
    end--;
    if (end > 0) {
        // First element of sorted array
        elem = this.snippetArray.getFirst();
        // First element is textual
        if (elem.type == 0) {
            sb.append(elem.toHTML(this, level, levelCache, joins));
            // Move start position
            start++;
        }
        ;
        sb.append("</span>");
        // Last element of sorted array
        elem = this.snippetArray.getLast();
        // Create right context, if there is any
        rightContext.append("<span class=\"context-right\">");
        // Last element is textual
        if (elem != null && elem.type == 0) {
            rightContext.append(elem.toHTML(this, level, levelCache, joins));
            // decrement end
            end--;
        }
        ;
    }
    ;
    if (this.endMore)
        rightContext.append("<span class=\"more\"></span>");
    rightContext.append("</span>");
    // Iterate through all remaining elements
    sb.append("<span class=\"match\">");
    for (short i = start; i <= end; i++) {
        elem = this.snippetArray.get(i);
        // UNTESTED
        if (elem != null) {
            String elemString = elem.toHTML(this, level, levelCache, joins);
            if (DEBUG) {
                log.trace("Add node {}", elemString);
            }
            ;
            sb.append(elemString);
        }
    }
    ;
    sb.append("</span>");
    sb.append(rightContext);
    return (this.snippetHTML = sb.toString());
}
Also used : FixedBitSet(org.apache.lucene.util.FixedBitSet) HighlightCombinatorElement(de.ids_mannheim.korap.response.match.HighlightCombinatorElement) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty)

Example 12 with JsonProperty

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

the class CandlepinSwaggerModelConverter method parseProperty.

private void parseProperty(ModelConverterContext context, boolean isNested, final BeanDescription beanDesc, Set<String> propertiesToIgnore, List<Property> props, BeanPropertyDefinition propDef) {
    Property property = null;
    String propName = propDef.getName();
    Annotation[] annotations = null;
    propName = getPropName(propDef, propName);
    PropertyMetadata md = propDef.getMetadata();
    boolean hasSetter = false, hasGetter = false;
    if (propDef.getSetter() == null) {
        hasSetter = false;
    } else {
        hasSetter = true;
    }
    if (propDef.getGetter() != null) {
        JsonProperty pd = propDef.getGetter().getAnnotation(JsonProperty.class);
        if (pd != null) {
            hasGetter = true;
        }
    }
    Boolean isReadOnly = null;
    if (!hasSetter & hasGetter) {
        isReadOnly = Boolean.TRUE;
    } else {
        isReadOnly = Boolean.FALSE;
    }
    final AnnotatedMember member = propDef.getPrimaryMember();
    if (member != null && !propertiesToIgnore.contains(propName) && /**
     * If the owning type is nested than we should include only those
     * fields that have the Hateoas annotation.
     */
    !(isNested && !member.hasAnnotation(HateoasInclude.class))) {
        List<Annotation> annotationList = new ArrayList<>();
        for (Annotation a : member.annotations()) {
            annotationList.add(a);
        }
        annotations = annotationList.toArray(new Annotation[annotationList.size()]);
        ApiModelProperty mp = member.getAnnotation(ApiModelProperty.class);
        if (mp != null && mp.readOnly()) {
            isReadOnly = mp.readOnly();
        }
        Type nested = null;
        JavaType propType = member.getType(beanDesc.bindingsForBeanType());
        JsonFilter jsonFilter = propType.getRawClass().getAnnotation(JsonFilter.class);
        /**
         * At this point the propType is a type of some nested field of the
         * type that is being processed. The condition checks if this
         * particular type should have Hateoas serialization enabled. In
         * other words, if we should create a new Nested* model.
         */
        if (jsonFilter != null && (jsonFilter.value().equals("ConsumerFilter") || jsonFilter.value().equals("EntitlementFilter") || jsonFilter.value().equals("OwnerFilter") || jsonFilter.value().equals("GuestFilter"))) {
            if (!nestedJavaTypes.containsKey(propType)) {
                nestedJavaTypes.put(propType, new NestedComplexType(propType));
            }
            nested = nestedJavaTypes.get(propType);
        } else {
            nested = propType;
        }
        // allow override of name from annotation
        if (mp != null && !mp.name().isEmpty()) {
            propName = mp.name();
        }
        if (mp != null && !mp.dataType().isEmpty()) {
            property = resolveApiAnnotated(context, property, annotations, mp, propType);
        }
        // no property from override, construct from propType
        if (property == null) {
            if (mp != null && StringUtils.isNotEmpty(mp.reference())) {
                property = new RefProperty(mp.reference());
            } else if (member.getAnnotation(JsonIdentityInfo.class) != null) {
                property = GeneratorWrapper.processJsonIdentity(propType, context, pMapper, member.getAnnotation(JsonIdentityInfo.class), member.getAnnotation(JsonIdentityReference.class));
            }
            if (property == null) {
                property = context.resolveProperty(nested, annotations);
            }
        }
        if (property != null) {
            addMetadataToProperty(property, propName, md, isReadOnly, member, mp);
            applyBeanValidatorAnnotations(property, annotations);
            props.add(property);
        }
    }
}
Also used : ApiModelProperty(io.swagger.annotations.ApiModelProperty) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) JsonIdentityReference(com.fasterxml.jackson.annotation.JsonIdentityReference) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) RefProperty(io.swagger.models.properties.RefProperty) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) Type(java.lang.reflect.Type) JavaType(com.fasterxml.jackson.databind.JavaType) PrimitiveType(io.swagger.util.PrimitiveType) JavaType(com.fasterxml.jackson.databind.JavaType) JsonIdentityInfo(com.fasterxml.jackson.annotation.JsonIdentityInfo) JsonFilter(com.fasterxml.jackson.annotation.JsonFilter) PropertyMetadata(com.fasterxml.jackson.databind.PropertyMetadata) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) UUIDProperty(io.swagger.models.properties.UUIDProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) AbstractNumericProperty(io.swagger.models.properties.AbstractNumericProperty) RefProperty(io.swagger.models.properties.RefProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) HateoasInclude(org.candlepin.common.jackson.HateoasInclude)

Example 13 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project phoenicis by PhoenicisOrg.

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)

Example 14 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project pinpoint by naver.

the class TransactionInfoViewModel method getApplicationMapData.

@JsonProperty("applicationMapData")
public Map<String, List<Object>> getApplicationMapData() {
    Map<String, List<Object>> result = new HashMap<String, List<Object>>();
    if (timeHistogramFormat == TimeHistogramFormat.V2) {
        for (Node node : nodes) {
            node.setTimeHistogramFormat(timeHistogramFormat);
        }
        for (Link link : links) {
            link.setTimeHistogramFormat(timeHistogramFormat);
        }
    }
    List<Object> nodeDataArray = new ArrayList<>(nodes);
    result.put("nodeDataArray", nodeDataArray);
    List<Object> linkDataArray = new ArrayList<>(links);
    result.put("linkDataArray", linkDataArray);
    return result;
}
Also used : HashMap(java.util.HashMap) Node(com.navercorp.pinpoint.web.applicationmap.nodes.Node) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Link(com.navercorp.pinpoint.web.applicationmap.link.Link) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty)

Example 15 with JsonProperty

use of com.fasterxml.jackson.annotation.JsonProperty in project chassis by Kixeye.

the class ConstructorParameterModelProperty method getModelProperties.

/**
 * Creates a collection of ConstructorParameterModelProperty objects from the arguments of the given ResolvedConstructor.
 * Only args annotated with @JsonProperty are included. Scala Case Classes are a special case and do not require the annotation.
 *
 * @param resolvedConstructor the constructor to get
 * @param alternateTypeProvider for resolving alternative types for the found arguments
 * @return the collection of ConstructorParameterModelProperty objects
 */
public static ImmutableList<ConstructorParameterModelProperty> getModelProperties(ResolvedConstructor resolvedConstructor, AlternateTypeProvider alternateTypeProvider) {
    Builder<ConstructorParameterModelProperty> listBuilder = new Builder<>();
    if (resolvedConstructor.getRawMember().getAnnotation(JsonCreator.class) != null || scala.Product.class.isAssignableFrom(resolvedConstructor.getDeclaringType().getErasedType())) {
        // constructor for normal classes must be annotated with @JsonCreator. Scala Case Classes are a special case
        for (int i = 0; i < resolvedConstructor.getArgumentCount(); i++) {
            AnnotationMap annotationMap = annotationMap(resolvedConstructor.getRawMember().getParameterAnnotations()[i]);
            ResolvedType parameterType = resolvedConstructor.getArgumentType(i);
            if (annotationMap.get(JsonProperty.class) != null) {
                listBuilder.add(new ConstructorParameterModelProperty(parameterType, alternateTypeProvider, annotationMap));
            }
        }
    }
    return listBuilder.build();
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) AnnotationMap(com.fasterxml.jackson.databind.introspect.AnnotationMap) Builder(com.google.common.collect.ImmutableList.Builder) ResolvedType(com.fasterxml.classmate.ResolvedType)

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