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

Possible incompatibility with Spring Boot #1140

Closed
Jaap-van-Hengstum opened this issue Jan 13, 2016 · 7 comments
Closed

Possible incompatibility with Spring Boot #1140

Jaap-van-Hengstum opened this issue Jan 13, 2016 · 7 comments

Comments

@Jaap-van-Hengstum
Copy link

@Jaap-van-Hengstum Jaap-van-Hengstum commented Jan 13, 2016

I've yet to test this with a clean version of Spring Boot but my guess is that this issue happens there also.

Spring Boot in HttpMessageConverters first adds the Spring Boot configured MappingJackson2HttpMessageConverter and then it adds the default MappingJackson2HttpMessageConverter from Spring MVC.

This causes the ObjectMapperConfigured event to fire twice, first for the configured converter (which is actually used) and then for the default converter. So when you f.e. set a custom property naming strategy then in ObjectMapperBeanPropertyNamingStrategythis is overwritten by the second event.

I've added the following code to my project to fix this:

@Configuration
public class MyWebAutoConfiguration extends WebMvcConfigurerAdapter {

    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        ObjectMapper objectMapper = null;
        for (HttpMessageConverter converter : converters) {
            if (converter instanceof MappingJackson2HttpMessageConverter) {
                MappingJackson2HttpMessageConverter jacksonConverter =
                        ((MappingJackson2HttpMessageConverter) converter);

                if (objectMapper == null) {
                    objectMapper = jacksonConverter.getObjectMapper();
                } else {
                    jacksonConverter.setObjectMapper(objectMapper);
                }
            }
        }
    }
}
@dilipkrish
Copy link
Member

@dilipkrish dilipkrish commented Jan 13, 2016

This is a known issue #1051, thank you for researching and providing a work around. I believe the issue of ObjectMapper selection needs to be fixed for sure.

@dilipkrish dilipkrish added this to the 2.4.0 milestone Jan 13, 2016
@Jaap-van-Hengstum
Copy link
Author

@Jaap-van-Hengstum Jaap-van-Hengstum commented Jan 13, 2016

The issue with Spring Boot is that it registers two MappingJackson2HttpMessageConverter converters. My guess is that the second converter is never used because both converters act upon the same media types (application/json). If that is the case then if there is more than one jackson converter, only the first converter for the application/json media type should fire te event.

(and Spring Boot should remove the redundant converter, but that's a Spring Boot issue)

@dilipkrish
Copy link
Member

@dilipkrish dilipkrish commented Jan 13, 2016

💡 moment! I think reversing the order will just fix it for 90% of the cases right?

@Jaap-van-Hengstum
Copy link
Author

@Jaap-van-Hengstum Jaap-van-Hengstum commented Jan 13, 2016

💡 moment! I think reversing the order will just fix it for 90% of the cases right?

That would probably work in most cases.

dilipkrish added a commit that referenced this issue Jan 14, 2016
This is a naive fix to the problem. Simply reversing the order in which the message processors are
iterated over will fix 80% of the reported issues with not using the correct object mapper.

fixes #1051, #1140
@dilipkrish dilipkrish closed this in 76e2f7d Mar 2, 2016
@zhaoxi1988
Copy link

@zhaoxi1988 zhaoxi1988 commented Dec 13, 2019

it also appears in spring boot 1.5

@kepha-korbit
Copy link

@kepha-korbit kepha-korbit commented Jul 9, 2020

https://springfox.github.io/springfox/docs/snapshot/

I have installed springfox for spring-boot but generated json data(/v2/ap-docs) have errors .

  • originalRef KEYWORD make error as following ::
    Structural error at definitions.LneQuest.properties.quizList.items
    should NOT have additional properties
    additionalProperty: originalRef
/internal/v1/quest/list3:
    get:
      tags:
        - lne-quest-controller
      summary: getLneQuestList3
      operationId: getLneQuestList3UsingGET
      produces:
        - '*/*'
      parameters:
        - name: from
          in: query
          description: from
          required: false
          type: string
          format: date-time
        - name: offset
          in: query
          required: false
          type: integer
          format: int64
        - name: paged
          in: query
          required: false
          type: boolean
        - name: pageNumber
          in: query
          required: false
          type: integer
          format: int32
        - name: pageSize
          in: query
          required: false
          type: integer
          format: int32
        - name: sort.sorted
          in: query
          required: false
          type: boolean
        - name: sort.unsorted
          in: query
          required: false
          type: boolean
        - name: to
          in: query
          description: to
          required: false
          type: string
          format: date-time
        - name: type
          in: query
          description: type
          required: false
          type: string
        - name: unpaged
          in: query
          required: false
          type: boolean
      responses:
        '200':
          description: OK
          schema:
            $ref: '#/definitions/Response'
            **originalRef**: Response
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
@dilipkrish
Copy link
Member

@dilipkrish dilipkrish commented Jul 9, 2020

Replied here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants