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
* @since 4.2
*/
protected Class<?> getSerializationView(Object conversionHint) {
if (conversionHint instanceof MethodParameter) {
MethodParameter param = (MethodParameter) conversionHint;
JsonView annotation = (param.getParameterIndex() >= 0 ? param.getParameterAnnotation(JsonView.class) : param.getMethodAnnotation(JsonView.class));
if (annotation != null) {
return extractViewClass(annotation, conversionHint);
}
} else if (conversionHint instanceof JsonView) {
return extractViewClass((JsonView) conversionHint, conversionHint);
} else if (conversionHint instanceof Class) {
return (Class<?>) conversionHint;
}
// No JSON view specified...
return null;
}
use of com.fasterxml.jackson.annotation.JsonView in project spring-framework by spring-projects.
the class Jackson2ServerHttpMessageReader method resolveReadHints.
@Override
protected Map<String, Object> resolveReadHints(ResolvableType streamType, ResolvableType elementType, ServerHttpRequest request) {
Object source = streamType.getSource();
MethodParameter parameter = (source instanceof MethodParameter ? (MethodParameter) source : null);
if (parameter != null) {
JsonView annotation = parameter.getParameterAnnotation(JsonView.class);
if (annotation != null) {
Class<?>[] classes = annotation.value();
if (classes.length != 1) {
throw new IllegalArgumentException("@JsonView only supported for read hints with exactly 1 class argument: " + parameter);
}
return Collections.singletonMap(AbstractJackson2Codec.JSON_VIEW_HINT, classes[0]);
}
}
return Collections.emptyMap();
}
use of com.fasterxml.jackson.annotation.JsonView in project spring-framework by spring-projects.
the class JsonViewResponseBodyAdvice method beforeBodyWriteInternal.
@Override
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {
JsonView annotation = returnType.getMethodAnnotation(JsonView.class);
Class<?>[] classes = annotation.value();
if (classes.length != 1) {
throw new IllegalArgumentException("@JsonView only supported for response body advice with exactly 1 class argument: " + returnType);
}
bodyContainer.setSerializationView(classes[0]);
}
use of com.fasterxml.jackson.annotation.JsonView in project ocvn by devgateway.
the class OcdsController method ocdsPackages.
@ApiOperation(value = "Returns all available packages, filtered by the given criteria." + "This will contain the OCDS package information (metadata about publisher) plus the release itself.")
@RequestMapping(value = "/api/ocds/package/all", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Public.class)
public List<ReleasePackage> ocdsPackages(@ModelAttribute @Valid final YearFilterPagingRequest releaseRequest) {
List<Release> ocdsReleases = ocdsReleases(releaseRequest);
List<ReleasePackage> releasePackages = new ArrayList<>(ocdsReleases.size());
for (Release release : ocdsReleases) {
releasePackages.add(createReleasePackage(release));
}
return releasePackages;
}
use of com.fasterxml.jackson.annotation.JsonView in project spring-framework by spring-projects.
the class JsonViewRequestBodyAdvice method beforeBodyRead.
@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> selectedConverterType) throws IOException {
JsonView annotation = methodParameter.getParameterAnnotation(JsonView.class);
Class<?>[] classes = annotation.value();
if (classes.length != 1) {
throw new IllegalArgumentException("@JsonView only supported for request body advice with exactly 1 class argument: " + methodParameter);
}
return new MappingJacksonInputMessage(inputMessage.getBody(), inputMessage.getHeaders(), classes[0]);
}
Aggregations