官术网_书友最值得收藏!

Configuring custom HttpMessageConverters

While we were building our RESTful web data service, we defined the controllers, repositories, and put some annotations on them; but nowhere did we do any kind of object translation from the Java entity beans to the HTTP data stream output. However, behind the scenes, Spring Boot automatically configured HttpMessageConverters so as to translate our entity beans into a JSON representation written to HTTP response using the Jackson library. When multiple converters are available, the most applicable one gets selected based on the message object class and the requested content type.

The purpose of HttpMessageConverters is to translate various object types into their corresponding HTTP output formats. A converter can either support a range of multiple data types or multiple output formats, or a combination of both. For example, MappingJackson2HttpMessageConverter can translate any Java object into application/json, whereas ProtobufHttpMessageConverter can only operate on instances of com.google.protobuf.Message but can write them to the wire as application/json, application/xml, text/plain, or application/x-protobuf. HttpMessageConverters support not only writing out to the HTTP stream but also converting HTTP requests to appropriate Java objects as well.

主站蜘蛛池模板: 冕宁县| 滕州市| 定安县| 毕节市| 增城市| 平阴县| 手机| 类乌齐县| 凤山县| 临沂市| 富裕县| 永昌县| 长宁区| 玉溪市| 高淳县| 措勤县| 栾川县| 大同县| 南澳县| 新和县| 霍山县| 龙游县| 广东省| 永兴县| 新宾| 衡阳县| 望都县| 太仓市| 丰县| 农安县| 绥化市| 上虞市| 界首市| 库伦旗| 信阳市| 德安县| 孟村| 淳化县| 竹溪县| 芮城县| 呼图壁县|