FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
310 stars 133 forks source link

[Protobuf] How to add support HttpMessageConverter to register in Spring Message converters. #119

Closed nazmul19 closed 6 years ago

nazmul19 commented 6 years ago

How we can use this library to convert the DTO object into protobuf response automatically in Spring REST Endpoint depending on produces Media Type in RequestMapping Annotation.

@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, 
                            "application/x-protobuf"})
    public UserDetail getUser(@PathVariable Long id){
        User user = userService.getUser(id);
        return modelMapper.map(user, UserDetail.class);
    }

If the request has header value "application/x-protobuf" for attribute "Accept" then response must be in protobuf / binary.

Currently written REST Endpoint working for "application/json" and "application/xml" correctly. Similar to this https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.html Note: This converter uses official google protobuf library.

cowtowncoder commented 6 years ago

Please send usage/design questions on mailing lists.

nazmul19 commented 6 years ago

What I want to achieve here is that write single rest api with different consume media type like application/json, application/XML and application/x-protobuf .

If client send accept header as application/x-protobuf then rest api content should be a x-protobuf bytes and all that should be handled out of the box similar to json or XML content handled by jackson http message converter.

How I can achieve the same in jackson protobuf format.

Let me know if you need more clarification.

cowtowncoder commented 6 years ago

I could have sworn I pointed out the way to proceed. Apparently not.

One of these:

https://groups.google.com/forum/#!forum/jackson-user https://groups.google.com/forum/#!forum/jackson-dev

(probably latter)

is the way to go. Not filing an issue for asking a question of how to write a component that allows this module to be used with a web framework.

nazmul19 commented 6 years ago

Thanks for pointers I will try. But if this module does not have integration capability similar to its other related module then what is the use of this. This is obvious expectation.

On Nov 16, 2017 10:01 PM, "Tatu Saloranta" notifications@github.com wrote:

I could have sworn I pointed out the way to proceed. Apparently not.

One of these:

https://groups.google.com/forum/#!forum/jackson-user https://groups.google.com/forum/#!forum/jackson-dev

(probably latter)

is the way to go. Not filing an issue for asking a question of how to write a component that allows this module to be used with a web framework.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FasterXML/jackson-dataformats-binary/issues/119#issuecomment-344978942, or mute the thread https://github.com/notifications/unsubscribe-auth/ADfKYClEMAczfUaE_pkw6ytrMJZ_JeuLks5s3GNagaJpZM4QgjHR .