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

Provide GSON-based Encoder/Decoder #27131

Open
asavov opened this issue Jul 5, 2021 · 11 comments
Open

Provide GSON-based Encoder/Decoder #27131

asavov opened this issue Jul 5, 2021 · 11 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@asavov
Copy link

asavov commented Jul 5, 2021

Affects: 5.3.6 (coming from Spring Boot 2.4.5)

Requirement: Provide GSON-base Encoder/Decoder by analogy with Jackson2JsonEncoder/Jackson2JsonDecoder (in webflux world) and GsonHttpMessageConverter (in mvc world).

Issue found (status closed): spring-projects/spring-boot#9166

Workaround found: https://stackoverflow.com/questions/60854660/set-custom-encoder-decoder-or-typeadapter-for-webclient-using-gson

Let me know if I need to provide more details.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 5, 2021
@bclozel bclozel self-assigned this Jul 5, 2021
@bclozel
Copy link
Member

bclozel commented Jul 5, 2021

We've discussed this issue as a team and we can consider this as an improvement, but we're not yet 100% about its timeline.

Unlike Jackson, Gson doesn't support asynchronous parsing so we can't support the entire Decoder contract. Concretely, this means that:

  • we can't support Flux<Something> as a method parameter in controllers and handlers, even if the request is application/json
  • we can't support media types like nd-json as request input, as they're entirely streaming based

On the other hand, we could still support a partial implementation of the Encoder and Decoder contracts and this is already the case with the Jackson2CborDecoder:

  • Controller methods can accept Mono<List<Something>> as arguments - this means the entire request body will be buffered before deserialization. If the request bodies aren't too big, this shouldn't make a big difference at runtime.
  • On the writing side, there should be no limitation at all (Flux values and streaming both supported)

Would those limitations work for your use cases?

Note that as pointed out in the StackOverflow answer's comments, the proposed implementation is seriously flawed for the streaming use case, since it assumes that incoming DataBuffer properly split JSON objects - this is not the case and this is likely to cause parsing issues at runtime.

@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 5, 2021
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Jul 12, 2021
@spring-projects-issues
Copy link
Collaborator

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 19, 2021
@bclozel
Copy link
Member

bclozel commented Aug 2, 2021

It's not clear at this point whether a limited encoder/decoder support for GSON would be still helpful to the Spring community. If anyone is interested in this feature, please comment on this issue so we can reconsider this.

@chancekim
Copy link

Hello, I think a limited encoder/decoder would be really helpful to many users.
Our company is using spring MVC with GSON and planning to change our application to the Webflux based application.
There is a common request and response classes which are using GSON annotations now, but we have to change those classes to use jackson annotations because Webflux doesn't provide GSON encoder/decoder.
I guess it is happening to many other companies, so I politely request you reconsider of this issue.

@bclozel
Copy link
Member

bclozel commented Mar 16, 2022

Hi @chancekim - thanks for reaching out!
This is pretty late in the 5.3.x generation and we're working on the upcoming 6.0.x. Introducing a new feature in 5.3.x at this stage would be odd. Would that work for you if this is done for the 6.0.x line? What are your current plans for this MVC->WebFlux change?

@chancekim
Copy link

Hi @bclozel !
Yes, even though it will be included in the 6.0.x, it must be helpful, not only me but the others.

@bclozel bclozel added this to the 6.0.x milestone Mar 22, 2022
@bclozel bclozel added the type: enhancement A general enhancement label Mar 22, 2022
@bclozel bclozel reopened this Mar 22, 2022
@jhoeller jhoeller modified the milestones: 6.0.x, 6.x Backlog Jan 11, 2023
@bclozel bclozel removed their assignment Jan 25, 2023
@JevgenijZubovskij-UnlikelyAI
Copy link

Hi, wanted to double check if it's now possible to use this with 6.0.x WebFlux or is it still an upcoming feature? Asking as the setting spring.mvc.converters.preferred-json-mapper=gson does not seem to propagate to it and it continues using Jackson for deserialising WebClient HTTP payloads

@bclozel
Copy link
Member

bclozel commented Mar 10, 2023

@JevgenijZubovskij-UnlikelyAI this feature is not implemented and it's in the 6.X Backlog right now. We only got one person interested so far and we never got feedback on the limitations outlined above.

@shanewow
Copy link

The Stripe Java API (https://github.com/stripe/stripe-java) is a good use case. All of their models use Gson annotations. Having to re-write their models so they can be used in a WebFlux microservice has been a headache.

@bclozel
Copy link
Member

bclozel commented Mar 31, 2023

@shanewow would the limitations listed in #27131 (comment) be acceptable for your use case?

@jhoeller jhoeller added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Dec 23, 2023
@jhoeller jhoeller changed the title Provide GSON-base org.springframework.core.codec.Encoder/Decoder Provide GSON-based Encoder/Decoder Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants