Java Code Examples for com.fasterxml.jackson.annotation.JsonView#value()

The following examples show how to use com.fasterxml.jackson.annotation.JsonView#value() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MappingJackson2MessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Class<?> extractViewClass(JsonView annotation, Object conversionHint) {
	Class<?>[] classes = annotation.value();
	if (classes.length != 1) {
		throw new IllegalArgumentException(
				"@JsonView only supported for handler methods with exactly 1 class argument: " + conversionHint);
	}
	return classes[0];
}
 
Example 2
Source File: JsonViewRequestBodyAdvice.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter methodParameter,
		Type targetType, Class<? extends HttpMessageConverter<?>> selectedConverterType) throws IOException {

	JsonView ann = methodParameter.getParameterAnnotation(JsonView.class);
	Assert.state(ann != null, "No JsonView annotation");

	Class<?>[] classes = ann.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]);
}
 
Example 3
Source File: JsonViewResponseBodyAdvice.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType,
		MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {

	JsonView ann = returnType.getMethodAnnotation(JsonView.class);
	Assert.state(ann != null, "No JsonView annotation");

	Class<?>[] classes = ann.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]);
}
 
Example 4
Source File: Jackson2CodecSupport.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected Map<String, Object> getHints(ResolvableType resolvableType) {
	MethodParameter param = getParameter(resolvableType);
	if (param != null) {
		JsonView annotation = getAnnotation(param, JsonView.class);
		if (annotation != null) {
			Class<?>[] classes = annotation.value();
			Assert.isTrue(classes.length == 1, JSON_VIEW_HINT_ERROR + param);
			return Hints.from(JSON_VIEW_HINT, classes[0]);
		}
	}
	return Hints.none();
}
 
Example 5
Source File: MappingJackson2MessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Class<?> extractViewClass(JsonView annotation, Object conversionHint) {
	Class<?>[] classes = annotation.value();
	if (classes.length != 1) {
		throw new IllegalArgumentException(
				"@JsonView only supported for handler methods with exactly 1 class argument: " + conversionHint);
	}
	return classes[0];
}
 
Example 6
Source File: MappingJackson2MessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Class<?> extractViewClass(JsonView annotation, Object conversionHint) {
	Class<?>[] classes = annotation.value();
	if (classes.length != 1) {
		throw new IllegalArgumentException(
				"@JsonView only supported for handler methods with exactly 1 class argument: " + conversionHint);
	}
	return classes[0];
}
 
Example 7
Source File: JsonViewRequestBodyAdvice.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter methodParameter,
		Type targetType, Class<? extends HttpMessageConverter<?>> selectedConverterType) throws IOException {

	JsonView ann = methodParameter.getParameterAnnotation(JsonView.class);
	Assert.state(ann != null, "No JsonView annotation");

	Class<?>[] classes = ann.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]);
}
 
Example 8
Source File: JsonViewResponseBodyAdvice.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType,
		MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {

	JsonView ann = returnType.getMethodAnnotation(JsonView.class);
	Assert.state(ann != null, "No JsonView annotation");

	Class<?>[] classes = ann.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]);
}
 
Example 9
Source File: Jackson2CodecSupport.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected Map<String, Object> getHints(ResolvableType resolvableType) {
	MethodParameter param = getParameter(resolvableType);
	if (param != null) {
		JsonView annotation = getAnnotation(param, JsonView.class);
		if (annotation != null) {
			Class<?>[] classes = annotation.value();
			Assert.isTrue(classes.length == 1, JSON_VIEW_HINT_ERROR + param);
			return Hints.from(JSON_VIEW_HINT, classes[0]);
		}
	}
	return Hints.none();
}
 
Example 10
Source File: MappingJackson2MessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private Class<?> extractViewClass(JsonView annotation, Object conversionHint) {
	Class<?>[] classes = annotation.value();
	if (classes.length != 1) {
		throw new IllegalArgumentException(
				"@JsonView only supported for handler methods with exactly 1 class argument: " + conversionHint);
	}
	return classes[0];
}
 
Example 11
Source File: JsonViewRequestBodyAdvice.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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]);
}
 
Example 12
Source File: JsonViewResponseBodyAdvice.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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]);
}
 
Example 13
Source File: MappingJackson2MessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private Class<?> extractViewClass(JsonView annotation, Object conversionHint) {
	Class<?>[] classes = annotation.value();
	if (classes.length != 1) {
		throw new IllegalArgumentException(
				"@JsonView only supported for handler methods with exactly 1 class argument: " + conversionHint);
	}
	return classes[0];
}
 
Example 14
Source File: JsonViewRequestBodyAdvice.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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]);
}
 
Example 15
Source File: JsonViewResponseBodyAdvice.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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]);
}