Skip to content

Provide Gson/JSON-B MessageConverter for spring-messaging (aligned with spring-web) #21496

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

Closed
spring-projects-issues opened this issue Jun 20, 2018 · 8 comments
Assignees
Labels
in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Marten Deinum opened SPR-16958 and commented

When using messaging there are MessageConverter implementations using Jackson to marshall message from/to JSON. However there doesn't seem to be one for GSON whereas there is GSON support in the web area. 

Now when using both messaging and web and when using GSON and want to use JSON for marshaling you need both providers on the class path. It would be nice if we could use GSON in the messaging area as well. 


Affects: 5.0.7

Referenced from: pull request #1863

@spring-projects-issues
Copy link
Collaborator Author

Marten Deinum commented

Pull request available. 

Including:

  • Central management of GSON dependency
  • JMS based MessageConverter (introduced a base class for both GSON and Jackson based MessageConverter s
  • Generic MessageConverter
  • Tests

@spring-projects-issues spring-projects-issues added in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.x Backlog milestone Jan 11, 2019
@fo0
Copy link

fo0 commented Jul 15, 2020

pretty nice feature, any plans for merge/integration?

@gaxpay
Copy link

gaxpay commented Sep 16, 2020

I would love to see this included! Great contribution @mdeinum 👍

@jhoeller jhoeller self-assigned this Sep 16, 2020
@jhoeller
Copy link
Contributor

In the meantime, we don't just have GSON to deal with but also JSON-B with Apache Johnzon as the common implementation. The number of message converter implementations would rise significantly... and I'm not sure all of them are destined to be first-class citizens in a 2020 scenario.

Which variants are you specifically interested in? If it is indeed GSON, would it be the JMS variant or the spring-messaging variant?

@mdeinum
Copy link
Contributor

mdeinum commented Sep 17, 2020

I assume the question is for @gaxpay and not me. But the initial contribution was to align the supported JSON implementation from the web to messaging (and JMS) as well. Isn't it a bit strange to support something for the web but not for messaging in regards to first-class citizens? Wouldn't that also be a source of problems, especially in regards to auto-configuration as which JSON implementation would be used (GSON for the web and Jackson for messaging?).

Currently, it might make more sense to place them in spring-messaging instead of spring-jms for a broader application. The messaging ones can be adapted to JMS quite easily, the other way around not so much.

@jhoeller
Copy link
Contributor

The inconsistency is definitely worth addressing in some form; I just wonder where to draw the line.

The Jackson JMS converter is a bit special in terms of its type id handling, inferring the JSON type from the JMS message itself, whereas the spring-messaging converter arrangement assumes an explicit target class being given by the caller (like the web converter abstraction). I'm not sure about extending the JMS arrangement there at this late point, not least of it all because it is being mirrored in the Spring AMQP project where there is Jackson support with the same type id arrangement.

On a related note, we recently added Protobuf and Protobuf-JSON converter to spring-messaging (#24022), aligning with the ones in spring-web. From that perspective, adding GSON and JSON-B converters there as well would make a lot of sense from a consistency perspective. I'll see what we can do about that for 5.3 RC2 still.

@jhoeller jhoeller modified the milestones: 5.x Backlog, 5.3 RC2 Sep 17, 2020
@gaxpay
Copy link

gaxpay commented Sep 17, 2020

My view of it was the same as mentioned above, namely consistency across borders of web vs messaging and the auto-configurations.
The proposed road ahead for aligning spring-messaging and spring-web makes sense.

@jhoeller jhoeller changed the title Provide a GSON JMS/Messaging MessageConverter [SPR-16958] Provide a Gson / JSON-B MessageConverter for spring-messaging Sep 24, 2020
@jhoeller
Copy link
Contributor

I've repurposed this issue for the Gson / JSON-B (Apache Johnzon) alignment in spring-messaging, with the primary target being WebSocket support. My local implementations are designed with a common base class, similar to the arrangement in spring-web, and similarly included in our default WebSocket configuration based on classpath presence. To be committed ASAP.

@jhoeller jhoeller changed the title Provide a Gson / JSON-B MessageConverter for spring-messaging Provide Gson/JSON-B MessageConverter for spring-messaging (aligned with spring-web) Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants