JPA映射MySQL json类型,字符串出现乱码 [英] JPA map MySQL json type, got garbled string

查看:481
本文介绍了JPA映射MySQL json类型,字符串出现乱码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AttributeConverter将MySQL JSON列转换为Object,如 https://stackoverflow.com/a/31547965/中所述1633272

I'm using AttributeConverter to convert MySQL JSON column to Object as mentioned in https://stackoverflow.com/a/31547965/1633272

当将数据存储到MySQL中时,它工作正常,我可以在WorkBench中看到正确的值.

It works fine when storing data into MySQL, I can see the correct values in WorkBench.

但是,当将列返回到Java应用程序时,一个Unicode字符映射为3个字符.

But, when getting the column back to java application, one unicode char is mapped into 3 chars.

这里是一个示例,JSON字符串中" 仅有1个用引号引起来的unicode字符.在评估表达式窗口中,我可以看到它被映射为

Here's an example, the JSON string "中" just has 1 unicode char wrapped by quotes. In Evaluation Expression window I can see it is mapped as

0 = '"' 34
1 = 'ä' 228
2 = '¸' 184
3 = '\u00AD' 173
4 = '"' 34

我正在使用的库:

'mysql:mysql-connector-java:5.1.39',
'org.springframework.data:spring-data-jpa:1.9.0.RELEASE',
'org.hibernate:hibernate-entitymanager:5.0.6.Final',

似乎这是MySQL的已知问题: https://bugs.mysql.com/bug.php?id=80631

Seems it is a known issue for MySQL: https://bugs.mysql.com/bug.php?id=80631

推荐答案

此错误已在mysql-connector-java:5.1.40

This bug has been fixed in mysql-connector-java:5.1.40

这篇关于JPA映射MySQL json类型,字符串出现乱码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆