Skip to content

JsonView support for JMS [SPR-13237] #17828

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 Jul 15, 2015 · 9 comments
Closed

JsonView support for JMS [SPR-13237] #17828

spring-projects-issues opened this issue Jul 15, 2015 · 9 comments
Assignees
Labels
in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 15, 2015

doom777 opened SPR-13237 and commented

Just like MappingJackson2HttpMessageConverter now supports JsonView, so too should MappingJackson2MessageConverter.

Also would be nice to set JsonView, or just a Class in JmsTemplate.convertAndSend


Issue Links:

Referenced from: commits faab220, dc8de51

1 votes, 9 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 16, 2015

Juergen Hoeller commented

We don't necessarily need to bake @JsonView support into our JMS MappingJackson2MessageConverter variant... With 4.1's @JmsListener model and our JmsMessagingTemplate, we should be able to benefit from our generic MappingJackson2MessageConverter's @JsonView support (as introduced through #17338).

Stéphane, let's find out where we're at with this. There might just be very little missing in order to make this work with JMS properly.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

We still have time to add support of @JsonView on @JmsListener annotated endpoint. Your jmsTemplate part is different and won't be handled in this issue. Thanks.

@spring-projects-issues
Copy link
Collaborator Author

doom777 commented

I realize that there isn't enough time to push this into 4.2 GA, however this is still important functionality, and the workaround is currently ugly. If you already implemented functionality to use custom views on MessageMappings and MessageSubscriptionMappins, then you should also have it on jmsTemplate.convertAndSend, since it's also a first-class pathway into sending messages to the client.

At the very least make MappingJackson2MessageConverter.convertToInternal protected, so I can overwrite it and send my JsonView in the headers, kind of like you are already doing with MessageMappings

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

"would be nice" does not sound like important functionality to me :-) But granted, I'll have a look at that use case to see if we can improve the experience on the sending part as well.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I'm moving this to the backlog since support for @JsonView for incoming as well as outgoing JMS messages turns out to be rather involved. Let's get feedback on the MVC and STOMP support for it first... and then do a comprehensive JMS approach for 4.3.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

doom777 commented

The way it is now is almost there. Now I can do
template.convertAndSend("/topic/search."+searchId,
body,
Collections.singletonMap(
AbstractMessageSendingTemplate.CONVERSION_HINT_HEADER, Body.class));

The only problem is that the main MessageConverter is the delegating CompositeMessageConverter, which does not support public final Message<?> toMessage(Object payload, MessageHeaders headers, Object conversionHint).
I am forced to manually set the template's messageconverter like this:
MappingJackson2MessageConverter messageConverter = new MappingJackson2MessageConverter();
messageConverter.setObjectMapper(appContext.getBean("objectMapper", ObjectMapper.class));
template.setMessageConverter(messageConverter);

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Aug 12, 2015

Juergen Hoeller commented

Good point. I've created #17927 for that purpose, introducing a SmartMessageConverter interface with those conversionHint variants, which CompositeMessageConverter is then able to implement. Scheduled for 4.2.1.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This SmartMessageConverter support will be available in the upcoming 4.2.1.BUILD-SNAPSHOT. Please give it a try!

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

This has been merged to master and should be available in a couple of hours. I have created a sample project that showcases what you can do with it.

Sending a message with a given JSonView is as straightforward as invoking the converter with the JSonView to use from a MessageCreator. On the receiving side, you can add a @JsonView in an @JmsListener annotated method to define the view to use for the reply.

Please give that a try and let me know if there is any issue. Thanks!

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) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants