Added AutoConfigure for MessagePack. MessagePack is an efficient binary serialization format. It's like JSON but fast and small.

This PR supports MessagePack by adding HttpMessageConverter for MessagePack to Spring MVC and RestTemplate.

Only HTTP clients have to do is specifying Accept header with application/x-msgpack to access the MessagePack format.

This format would be helpful for the communication between services.

Comment From: philwebb

Thanks for the PR. We're going to mark this one as "waiting-for-votes" and see how much demand there is.

Comment From: eiryu

+1 😁

Comment From: quitada41

+1

Comment From: frsyuki

+1 :+1: This is a great especially when I implement a reliable client library because msgpack has less unexpected troubles with floating point numbers...JSON can't serialize NaN.

Comment From: bobbyjam99-zz

+1

Comment From: destan

+1

It's weird to wait for votes to have it merged but anyways...

Comment From: sthzg

+1

Comment From: snicoll

@rstoyanchev did you consider supporting MessagePack in Spring MVC?

Comment From: bclozel

Not that I know - there's no issue in the Spring Framework tracker. We're supporting google protobuf already (to be upgraded in Spring 4.3).

I guess we can also consider MessagePack or Flatbuffers. The problem with those serialization formats: we don't always know if/how those libraries will be maintained; even the big players seem to change their minds a lot...

Comment From: making

I sent PR to not Spring Framework but Spring Boot because this is a kind of configuration. Just adding MessagePackFactory to ObjectMapper.

Supporting by Spring MVC sounds great, but I think auto-configuration would be enough.

Comment From: snicoll

My question was not meant to integrate this in Spring Framework. I asked to better understand why it's not supported and Brian just gave us the info that we need.

Comment From: wilkinsona

It's weird to wait for votes to have it merged but anyways...

@destan It's not weird when you consider the ongoing cost after a PR has been merged, such as: - It's another feature for users to understand - It's more code for us to maintain - It's another dependency for us to track and upgrade

Comment From: frsyuki

@bclozel I'm one of the committers of msgpack-java. The latest version is v0.8.1, which was released yesterday.

Comment From: rstoyanchev

This PR does have some parts that arguably should be in the Spring Framework, in particular the new HttpMessageConverter. That said looking at the converter:

public class MessagePackHttpMessageConverter extends AbstractJackson2HttpMessageConverter {
    public MessagePackHttpMessageConverter() {
        super(new ObjectMapper(new MessagePackFactory()),
                new MediaType("application", "x-msgpack"));
    }
 }

Isn't that just a MappingJackson2HttpMessageConverter with a provided ObjectMapper instance and different default content type? It looks a lot like the MappingJackson2XmlHttpMessageConverter which brings up the point that the Jackson2ObjectMapperBuilder should be used to create the ObjectMapper to ensure the same defaults.

In any case it seems like a relatively minor investment on the part of the Spring Framework if such a converter were to be added there.

Comment From: making

@rstoyanchev Thank you for your nice advice. I've updated PR to use Jackson2ObjectMapperBuilder.

Comment From: quitada41

+1

Comment From: uweschaefer

+1

Comment From: 0xbillw

+1

Comment From: LtTempletonPeck

+1

Comment From: re-thc

+1

Comment From: making

closing since MessagePack hasn't supported Jackson 2.9 yet

Comment From: sergey-morenets

Any updates on this? There's Jackson extension that integrates MessagePack

Comment From: venkata6

yes, it will be nice if springboot supports messagepack soon

Comment From: wilkinsona

@sergey-morenets I assume you are referring to jackson-dataformat-msgpack? That's the Jackson extension that this pull request proposes to use. It seems to be building against Jackson 2.9 so it's not clear that it'll work for us as Spring Boot depends on Jackson 2.11.

@making what's your opinion on the current state of things here?

Comment From: making

As of sending the PR, I wanted the project to follow Jackson's version upgrade, but it wasn't. I don't think it's a good idea to include this feature in Spring Boot, as it could prevent Spring Boot from getting Jackson versions up.

@sergey-morenets @venkata6 If you want to serialize/deserialize MessagePack data with Spring Boot, just configuring below should work.

<dependency>
    <groupId>org.msgpack</groupId>
    <artifactId>jackson-dataformat-msgpack</artifactId>
    <version>0.8.20</version>
</dependency>
@Bean
public HttpMessageConverter<Object> messagePackHttpMessageConverter(Jackson2ObjectMapperBuilder builder) {
    return new AbstractJackson2HttpMessageConverter(builder.factory(new MessagePackFactory()).build(), new MediaType("application", "x-msgpack")) {
    };
}

Comment From: wilkinsona

Thanks very much, @making.