Search in sources :

Example 6 with JsonView

use of com.fasterxml.jackson.annotation.JsonView in project spring-framework by spring-projects.

the class MappingJackson2MessageConverter method getSerializationView.

/**
	 * Determine a Jackson serialization view based on the given conversion hint.
	 * @param conversionHint the conversion hint Object as passed into the
	 * converter for the current conversion attempt
	 * @return the serialization view class, or {@code null} if none
	 */
protected Class<?> getSerializationView(Object conversionHint) {
    if (conversionHint instanceof MethodParameter) {
        MethodParameter methodParam = (MethodParameter) conversionHint;
        JsonView annotation = methodParam.getParameterAnnotation(JsonView.class);
        if (annotation == null) {
            annotation = methodParam.getMethodAnnotation(JsonView.class);
            if (annotation == null) {
                return null;
            }
        }
        return extractViewClass(annotation, conversionHint);
    } else if (conversionHint instanceof JsonView) {
        return extractViewClass((JsonView) conversionHint, conversionHint);
    } else if (conversionHint instanceof Class) {
        return (Class<?>) conversionHint;
    } else {
        return null;
    }
}
Also used : JsonView(com.fasterxml.jackson.annotation.JsonView) MethodParameter(org.springframework.core.MethodParameter)

Example 7 with JsonView

use of com.fasterxml.jackson.annotation.JsonView in project spring-framework by spring-projects.

the class Jackson2ServerHttpMessageWriter method resolveWriteHints.

@Override
protected Map<String, Object> resolveWriteHints(ResolvableType streamType, ResolvableType elementType, MediaType mediaType, ServerHttpRequest request) {
    Map<String, Object> hints = new HashMap<>();
    Object source = streamType.getSource();
    MethodParameter returnValue = (source instanceof MethodParameter ? (MethodParameter) source : null);
    if (returnValue != null) {
        JsonView annotation = returnValue.getMethodAnnotation(JsonView.class);
        if (annotation != null) {
            Class<?>[] classes = annotation.value();
            if (classes.length != 1) {
                throw new IllegalArgumentException("@JsonView only supported for write hints with exactly 1 class argument: " + returnValue);
            }
            hints.put(AbstractJackson2Codec.JSON_VIEW_HINT, classes[0]);
        }
    }
    return hints;
}
Also used : HashMap(java.util.HashMap) JsonView(com.fasterxml.jackson.annotation.JsonView) MethodParameter(org.springframework.core.MethodParameter)

Example 8 with JsonView

use of com.fasterxml.jackson.annotation.JsonView in project ocvn by devgateway.

the class LocationInfowindowController method awardsByLocation.

@ApiOperation(value = "Displays the awards, filtered by location. See the location filter " + "for the options to filter by")
@RequestMapping(value = "/api/awardsByLocation", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Public.class)
public List<DBObject> awardsByLocation(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    Aggregation agg = newAggregation(match(where("awards.0").exists(true).orOperator(where("tender.items.deliveryLocation._id").exists(true), where("planning.budget.projectLocation._id").exists(true)).andOperator(getYearDefaultFilterCriteria(filter, "awards.date"))), project("awards").andExclude(Fields.UNDERSCORE_ID), unwind("awards"), skip(filter.getSkip()), limit(filter.getPageSize()));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> tagCount = results.getMappedResults();
    return tagCount;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) DBObject(com.mongodb.DBObject) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with JsonView

use of com.fasterxml.jackson.annotation.JsonView in project ocvn by devgateway.

the class LocationInfowindowController method tendersByLocation.

@ApiOperation(value = "Displays the tenders filtered by location. See the location filter " + "for the options to filter by")
@RequestMapping(value = "/api/tendersByLocation", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Public.class)
public List<DBObject> tendersByLocation(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    Aggregation agg = newAggregation(match(where("tender").exists(true).orOperator(where("tender.items.deliveryLocation._id").exists(true), where("planning.budget.projectLocation._id").exists(true)).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), project("tender").andExclude(Fields.UNDERSCORE_ID), skip(filter.getSkip()), limit(filter.getPageSize()));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> tagCount = results.getMappedResults();
    return tagCount;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) DBObject(com.mongodb.DBObject) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with JsonView

use of com.fasterxml.jackson.annotation.JsonView in project ocvn by devgateway.

the class LocationInfowindowController method planningByLocation.

@ApiOperation(value = "Displays the planning items, filtered by location. See the location filter " + "for the options to filter by")
@RequestMapping(value = "/api/planningByLocation", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Public.class)
public List<DBObject> planningByLocation(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    Aggregation agg = newAggregation(match(where("planning.budget").exists(true).orOperator(where("tender.items.deliveryLocation._id").exists(true), where("planning.budget.projectLocation._id").exists(true)).andOperator(getYearDefaultFilterCriteria(filter, "planning.bidPlanProjectDateApprove"))), project("planning").andExclude(Fields.UNDERSCORE_ID), skip(filter.getSkip()), limit(filter.getPageSize()));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> tagCount = results.getMappedResults();
    return tagCount;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) DBObject(com.mongodb.DBObject) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JsonView (com.fasterxml.jackson.annotation.JsonView)12 ApiOperation (io.swagger.annotations.ApiOperation)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 DBObject (com.mongodb.DBObject)4 MethodParameter (org.springframework.core.MethodParameter)4 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)4 Aggregation.newAggregation (org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation)4 Release (org.devgateway.ocds.persistence.mongo.Release)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ReleasePackage (org.devgateway.ocds.persistence.mongo.ReleasePackage)1 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1 MappingJacksonInputMessage (org.springframework.http.converter.json.MappingJacksonInputMessage)1