Mapping MySQL JSON Fields with MyBatis-Plus
Preface
MySQL supports fields of type JSON. In comparison to string-type fields, JSON fields offer the following advantages:
- Automatic validation of JSON syntax
- Underlying support for quick access to elements within the JSON. There’s no need to read the entire string and then parse it into a JSON object.
Logically, JSON is no different from a POJO. Spring MVC has already implemented automatic conversion between the two at the Controller tier, evident in request parameters and return values. So, how can the Repository tier achieve automatic conversion?
This article demonstrates achieving seamless, non-intrusive mapping (ORM) between JSON and POJO using MyBatis-Plus in the Repository tier.