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

Add JSON support to Protobuf codecs #25457

Closed
anborg opened this issue Jul 21, 2020 · 13 comments
Closed

Add JSON support to Protobuf codecs #25457

anborg opened this issue Jul 21, 2020 · 13 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@anborg
Copy link

anborg commented Jul 21, 2020

Use case: Developers want to create Protobuf service implementation, more efficient. However, also need to expose as rest/json, to support clients that consume json -- perhaps we are in technology-transition time?

This does not work for netty/webflux, but works for tomcat, so likely some platform config issue?

Please make it easy to expose PROTO implementation as rest, without code duplication.

image

https://stackoverflow.com/questions/60289736/spring-webflux-netty-no-tomcat-how-to-expose-proto-as-json-endopints-without/63022169#63022169

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 21, 2020
@anborg anborg changed the title Use case: Proto & Json with single implementation Netty: Proto & json api with single implementation Jul 21, 2020
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jul 22, 2020
@bucknerns
Copy link

+1

@sdeleuze
Copy link
Contributor

Protobuf support is provided in Spring WebFlux via ProtobufDecoder and ProtobufEncoder. Could you please check what prevents you to use that support?

@sdeleuze sdeleuze added the status: waiting-for-feedback We need additional information before we can continue label Nov 10, 2020
@bucknerns
Copy link

bucknerns commented Nov 11, 2020

Json serialization/deserialization doesn't work for protobufs when using webflux.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 11, 2020
@sdeleuze sdeleuze changed the title Netty: Proto & json api with single implementation Add JSON support to Protobuf codecs Nov 12, 2020
@sdeleuze
Copy link
Contributor

Ok I understand now, so this is about providing similar capablities than ProtobufJsonFormatHttpMessageConverter bu on codecs/WebFlux side.

@sdeleuze sdeleuze removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 12, 2020
@sdeleuze sdeleuze added this to the 5.x Backlog milestone Nov 12, 2020
@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: feedback-provided Feedback has been provided labels Nov 12, 2020
@bucknerns
Copy link

Any word on this?

@sazonenka
Copy link

Any updates on that?

@kitkars
Copy link

kitkars commented Apr 21, 2023

@rstoyanchev It would be great if you could prioritize this. We all see the benefit of webflux. but no support for protobuf :(

@rstoyanchev rstoyanchev modified the milestones: 6.x Backlog, 6.1.0-M1 Apr 25, 2023
@rstoyanchev
Copy link
Contributor

This should be feasible, just mirroring what we've already done on the HttpMessageConverter side. I've scheduled it to have a look for the upcoming 6.1 milestone.

@rstoyanchev rstoyanchev modified the milestones: 6.1.0-M1, 6.1.0-M2 Jun 13, 2023
@bclozel bclozel modified the milestones: 6.1.0-M2, 6.1.0-M3 Jul 10, 2023
@jhoeller jhoeller modified the milestones: 6.1.0-M3, 6.1.0-M4 Jul 17, 2023
@jhoeller jhoeller modified the milestones: 6.1.0-M4, 6.1.x Aug 15, 2023
@bclozel bclozel removed this from the 6.1.x milestone Oct 25, 2023
@bclozel bclozel added this to the 6.2.x milestone Oct 25, 2023
@bucknerns
Copy link

Updates?

@bclozel
Copy link
Member

bclozel commented Dec 18, 2023

@bucknerns we didn't get to this issue in time for 6.1. We're trying to prioritize specific themes and most requested features in our roadmap. We'll try to tackle this one in 6.2 but at two votes this hardly makes it a top priority right now.

@bclozel
Copy link
Member

bclozel commented Dec 18, 2023

@HubertWo please use the GitHub voting feature by adding your vote on the original issue comment. Writing "+1" comments just adds noise and is not counted against the total vote count.

@bucknerns
Copy link

@kitkars @sazonenka Can you plus the issue by hitting the thumbs up on the first comment.

@bclozel
Copy link
Member

bclozel commented Jun 18, 2024

Thanks to all for upvoting this issue. We now have a dedicated codec for Protobuf+JSON.

This comes with a noteworthy limitation: this codec does not support the deserialization of JSON arrays into Flux<Message>. We would need a non-blocking parser able to tokenize JSON arrray elements into DataBuffer. This is supported for Jackson, as Jackson itself provides a non-blocking parser in the first place. This is not the case for Protobuf Java Util and probably out of scope for this library.

In practice this means that Mono and Flux are supported as return types for WebFlux controllers signatures:

@GetMapping(path="/users", produces = "application/json")
Flux<User> listUsers();

@GetMapping(path="/users/{id}", produces = "application/json")
Mono<User> showUser(@Pathvariable String id);

But only Mono types are supported when reading request bodies:

@PostMapping(path="/users/create", consumes = "application/json")
Mono<Void> createUser(@RequestBody Mono<User> user)

// this case is not supported
@PostMapping(path="/users/createMany", consumes = "application/json")
Mono<Void> createUsers(@RequestBody Flux<User>> users)

// this should be used instead
@PostMapping(path="/users/createMany", consumes = "application/json")
Mono<Void> createUsers(@RequestBody Mono<List<User>> users)

We'll document further this support in #33063

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

10 participants