Get the App
SLTechnology News&Howtos  ›  Development  › 

In-depth Analysis of how to realize HttpMessageConverter message Information Converter

Shulou Source: shulou.com Published: 2022-06-02 04:07:46 10月03日 Update

How to realize the in-depth analysis of HttpMessageConverter message converter, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Preface

HttpMessageConverter, message information converter, converts a request message into a Java object, or a Java object into a response message.

HttpMessageConverter provides two annotations and two types: @ RequestBody,@ResponseBody,RequestEntity,ResponseEntity.

HttpMessageConverter introduction

Org.springframework.http.converter.HttpMessageConverter is a policy interface. The API description is as follows:

Strategy interface that specifies a converter that can convert from and to HTTP requests and responses. Simply put, it is a converter between HTTP request (request) and response (response). There are only five methods for this API. To put it simply, you can get a supported MediaType (such as application/json). When you receive a request, you can determine whether it can be read (canRead), and if you can read it (read); when you return the result, you can determine whether you can write (canWrite), and if you can write (write). You can first make an impression of these methods:

Boolean canRead (Class clazz, MediaType mediaType); boolean canWrite (Class clazz, MediaType mediaType); List getSupportedMediaTypes (); T read (Class)

Tags: Methods controllers annotations controls messages converters objects information identifiers browsers results formal parameters browsing formats examples types analysis that is interfaces problems Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Apple vpn MySQL Shulou Technology