In current post I am going to explain how to implement and register a custom Spring MVCHttpMessageConverter object. Specifically a converter that binds objects to Yaml protocol. As starting point I am going to use the Rest application I implemented in previous post. That application is a simple Restful application where XML and JSON (Spring MVC already support them) are used. Because Spring MVC does not implement YamlMessageConverter, I am going to explain how to transform previous application from supporting XML and JSON to support Yaml.
Yaml is a human-readable data serialization format that takes concepts from programming languages such as C, Perl, and Python, and ideas from XML and the data format of electronic mail (RFC 2822).
SnakeYAML is a YAML parser and emitter for the Java programming language, and will be used to implement our message converter.
Let's start with a UML class diagram of HttpMessageConverter that are going to be implemented.
HttpMessageConverter is a base interface that must be implemented. It is a strategy interface that specifies methods to convert objects from and to HTTP requests and responses.AbstractHttpMessageConverter is the abstract base class for most HttpMessageConverterimplementation (both provided by springframework), and is our base class.