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

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.

主站蜘蛛池模板: 杭州市| 交口县| 抚宁县| 图木舒克市| 扎兰屯市| 剑川县| 胶州市| 彩票| 鄄城县| 满洲里市| 新密市| 绥阳县| 安徽省| 宜阳县| 普格县| 封开县| 师宗县| 武安市| 蒙城县| 烟台市| 利辛县| 安国市| 舞阳县| 绥芬河市| 博白县| 建阳市| 丁青县| 徐水县| 莱西市| 贡山| 峨山| 安塞县| 隆安县| 永春县| 乌兰察布市| 昌宁县| 苍南县| 昌吉市| 祁阳县| 定安县| 阿拉尔市|