spring-data-redis - About spring data redis storage object json string, some unexpected characters appear in the value value
PHP中文网
PHP中文网 2017-05-31 10:31:22
0
2
934

I saved a json string of an object for each key in redis, but there were some strange characters when I took it out

this.redisTemplate.opsForValue().set(key, objectMapper.writeValueAsString(XXX),  15 * 1000);

This is the value code:

String xxxJSON= this.redisTemplate.opsForValue().get(key);

XXX xxx = objectMapper.readValue(xxxJSON, XXX.class);

This is the output:

redis取到的值====   NULNULNULNULNULNULNULNULNUL。。。。。{json 内容}                               

This is what you see in redis manager

\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00。。。。。。。。。。。。还有很多{json数据}

The previous NUL log output can be seen, but when copied, it is filled with spaces. In order to let everyone see the effect, the handwritten NUL

The main problem is that I need to convert the retrieved data into an object. If I remove the NUL in front of it, it can be converted into an object. If I add it, an error will be reported, but the copied data will be filled with spaces.
Other data Fortunately, there is no problem with set list or string. Only json string has this problem.

Has anyone encountered this problem? The main reason is that they don’t understand why this problem occurs. JSON strings are also strings. Why don’t ordinary strings have this problem? JSON strings have this problem.

Also try to use s to match space replacement and trim to remove the leading and trailing spaces, but it has no effect and the string is not transformed

PHP中文网
PHP中文网

认证0级讲师

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!