简体   繁体   中英

UTF-8 issue when using hibernate to store/retrieve JSON data from MySql

In my database table, there is a column named json_data, which is a JSON data type field. The according field in the entity class is @Column(name="json_data") String jsonData; .

Some data with UTF-8 characters are saved using entity.save() into database(something like \∂). When it's retrieved, the encoding is wrong, and I got character \ē.

My question is: what needs to be done in order to save/retrieve the JSON data type data from MySql using hibernate

Try like below:

ObjectMapper objMap=new ObjectMapper();
...
String jsonData = resultSet.getString("json_data");
Employee employee= (Employee) objMap.readValue(jsonData, Employee.class);
//replace Employee with your json java mapper class name
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM