Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonMappingException if ResponseStatus == NO_CONTENT (204) #641

Closed
Ichigo85 opened this issue May 4, 2020 · 3 comments
Closed

JsonMappingException if ResponseStatus == NO_CONTENT (204) #641

Ichigo85 opened this issue May 4, 2020 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@Ichigo85
Copy link

Ichigo85 commented May 4, 2020

Hi. I'm trying to make the migration to springdoc-openapi. After updating from 1.3.4 to 1.3.7 I have an error on java controller methods with annotation
@ResponseStatus(HttpStatus.NO_CONTENT).

Creating OpenApi json I receive this error

com.fasterxml.jackson.databind.JsonMappingException: Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) (through reference chain: io.swagger.v3.oas.models.OpenAPI["paths"]->io.swagger.v3.oas.models.Paths["/api/v0_6/operation/doSomething"]->io.swagger.v3.oas.models.PathItem["post"]->io.swagger.v3.oas.models.Operation["responses"]->io.swagger.v3.oas.models.responses.ApiResponses["null"])
@bnasslahsen
Copy link
Collaborator

bnasslahsen commented May 4, 2020

Hi @Ichigo85,

Could you please add a sample Hello Controller to reproduce your issue ?

Can you validate if you are having the same result with latest snaphot?

@Ichigo85
Copy link
Author

Ichigo85 commented May 4, 2020

Can you validate if you are having the same result with latest snaphot?

Unfortunately not, with 1.3.8 version configuration is not working anymore. I received an error

...
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springdoc.webmvc.core.SpringDocWebMvcConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@368239c8]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:477)
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:451)
	at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:154)
	... 45 more
Caused by: java.lang.NoClassDefFoundError: org/springdoc/core/GenericParameterBuilder

Here is a sample HelloController. I sincerely not sure what is the issue that triggers this error on responseMap. I have a similar (but smaller) controller and everything works fine. This HelloController is not working either.

@OpenAPIDefinition(
        info = @Info(
                title = "Hello controller",
                description = "Test error",
                version = "v0.1"
        )
)
@RestController
@RequestMapping(path = "/api/v0_1",
        produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ApiResponses(value = {
        @ApiResponse(responseCode = "400",
                description = StandardApiControllerV0_6.MESSAGE_400,
                content = @io.swagger.v3.oas.annotations.media.Content(mediaType = MediaType.APPLICATION_JSON_UTF8_VALUE,
                        schema = @Schema(implementation = ResponseError.class))
        ),
        @ApiResponse(responseCode = "401",
                description = StandardApiControllerV0_6.MESSAGE_401,
                content = @io.swagger.v3.oas.annotations.media.Content(mediaType = MediaType.APPLICATION_JSON_UTF8_VALUE,
                        schema = @Schema(implementation = OAuth2ResponseError.class))
        ),
        @ApiResponse(responseCode = "403",
                description = StandardApiControllerV0_6.MESSAGE_403,
                content = @io.swagger.v3.oas.annotations.media.Content(mediaType = MediaType.APPLICATION_JSON_UTF8_VALUE,
                        schema = @Schema(implementation = ResponseError.class))
        )
})
public class HelloController {

        @Operation(operationId="getSomething",
                summary="Find Something by various search parameters.",
                tags="Something",
                responses = {
                        @ApiResponse(responseCode = "200",
                                description = MESSAGE_200)
                })
        @RequestMapping(path = "something", method = { RequestMethod.GET })
        public String getSomething() {
                return "something";
        }
}

and this is the error:

2020-05-04 16:50:03.988 [main] INFO  org.springdoc.api.AbstractOpenApiResource - Init duration for springdoc-openapi is: 329 ms
2020-05-04 16:50:04.014 [main] ERROR org.shared.orchestica.btl.controller.GlobalControllerExceptionHandler - An error occured during call /swagger/api-docs
com.fasterxml.jackson.databind.JsonMappingException: Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) (through reference chain: io.swagger.v3.oas.models.OpenAPI["paths"]->io.swagger.v3.oas.models.Paths["/api/v0_1/something"]->io.swagger.v3.oas.models.PathItem["get"]->io.swagger.v3.oas.models.Operation["responses"]->io.swagger.v3.oas.models.responses.ApiResponses["null"])
	at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:285)
	at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1251)
	at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1145)
	at com.fasterxml.jackson.databind.ser.impl.FailingSerializer.serialize(FailingSerializer.java:35)
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeOptionalFields(MapSerializer.java:781)
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:639)
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:33)
	at com.fasterxml.jackson.databind.SerializerProvider.defaultSerializeValue(SerializerProvider.java:1033)
	at io.swagger.v3.core.jackson.ApiResponsesSerializer.serialize(ApiResponsesSerializer.java:35)
	at io.swagger.v3.core.jackson.ApiResponsesSerializer.serialize(ApiResponsesSerializer.java:11)
	at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
	at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:721)
	at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166)
	at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
	at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:721)
	at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166)
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeOptionalFields(MapSerializer.java:782)
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:639)
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:33)
	at com.fasterxml.jackson.databind.SerializerProvider.defaultSerializeValue(SerializerProvider.java:1033)
	at io.swagger.v3.core.jackson.PathsSerializer.serialize(PathsSerializer.java:35)
	at io.swagger.v3.core.jackson.PathsSerializer.serialize(PathsSerializer.java:11)
	at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
	at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:721)
	at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
	at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:4094)
	at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3404)
	at org.springdoc.webmvc.api.OpenApiResource.openapiJson(OpenApiResource.java:110)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

@bnasslahsen
Copy link
Collaborator

Might be duplicate of #630.
Unable to reproduce with the sample code provided.

Can be valdated with v1.3.8 released today.
The ticket can be reopened, if the relevant information to reproduce the issue are provided.

@bnasslahsen bnasslahsen added the duplicate This issue or pull request already exists label Jan 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants