Thanks to visit codestin.com
Credit goes to github.com

Skip to content

WebFlux returns 406 instead of RFC 7807 response for subtype of ProblemDetail #30533

@vijjayy81

Description

@vijjayy81

The following line causing 406 Error while using any subtype of ProblemDetail class.

		// For ProblemDetail, fall back on RFC 7807 format
		if (bestMediaType == null && elementType.toClass().equals(ProblemDetail.class)) {
			bestMediaType = selectMediaType(exchange, () -> getMediaTypesFor(elementType), this.problemMediaTypes);
		}

(https://github.com/spring-projects/spring-framework/blob/main/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java#L178)

The issue does not exists in Servlet as it checks the error body type is assignable of ProblemDetail class.

			// For ProblemDetail, fall back on RFC 7807 format
			if (compatibleMediaTypes.isEmpty() && ProblemDetail.class.isAssignableFrom(valueType)) {
				determineCompatibleMediaTypes(this.problemMediaTypes, producibleTypes, compatibleMediaTypes);
			}

https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java#L247

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions