Skip to content

Clarify the single class restriction with @JsonView for a response body advice [SPR-12270] #16875

@spring-projects-issues

Description

@spring-projects-issues

Alexey Krylov opened SPR-12270 and commented

Currently only one @JsonView class is used:

JsonViewResponseBodyAdvice.java:

	@Override
	protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType,
			MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {

		JsonView annotation = returnType.getMethodAnnotation(JsonView.class);
		Assert.isTrue(annotation.value().length != 0, "No view class in JsonView annotation on " + returnType);
		bodyContainer.setSerializationView(annotation.value()[0]);
	}

My code:

@JsonView({Category.Default.class, Product.Default.class})
   @RequestMapping("/catalog.json")
   public Collection<Category> getCatalog(@Named("deviceId") @RequestParam(value = "device_id", required = false) Integer deviceId) {
       return retrieveCatalog(deviceId);
   }

In this example only Category.Default.class will be used.
It will be very nice to have full support for @JsonView.


Affects: 4.1 GA

Referenced from: commits a3fd00e, ae43b17

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions