相关文章推荐
千年单身的充电器  ·  Canvas ...·  1 月前    · 
傻傻的大海  ·  在多语句TVF Sql ...·  1 年前    · 

接口因为编码不一致导致出错:

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Invalid UTF-8 middle byte 0x3f; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid UTF-8 middle byte 0x3f
 at [Source: (PushbackInputStream); line: 1, column: 27] (through reference chain: 
org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:283)
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:241)
	at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:205)

1.本地测试接口正常,发布项目正常启动,日志打印正常

2.通过测试环境调用接口报错:JSON parse error: Invalid UTF-8 middle byte 0x3f

定位问题:

本地测试正常,说明本地环境编码一致,其他接口正常调用,说明不是json解析配置的问题

因此可以基本判断是代码与服务器的编码不同所致,为了验证并解决问题,做如下判断性测试

解决方案:

1.请求的mapping上添加

@PostMapping(value = "XXX",produces = "application/json;charset=UTF-8")

现象:本地正常,测试环境异常,仍旧报错

结论:不是本地环境编码原因,如果是,所有传入汉字的接口都会异常。

2.pom中maven打包添加如下配置

<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>

<plugin>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-maven-plugin</artifactId>
       <configuration>
             <includeSystemScope>true</includeSystemScope>
             <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
       </configuration>
</plugin>

同时:启动bat文件中添加 java -Dfile.encoding=UTF-8 -jar  -Xms2048m -Xmx2048m XXXX.jar --spring.profiles.active=test

现象:本地正常,测试环境正常,但是控制台输出日志为乱码

结论:可以得出配置生效,环境统一,但是控制台日志为乱码,确定是测试环境编码的问题

3.保持2的配置不变,查询实时打印日志窗口编码格式

logback日志控制台打印日志编码格式换为GBK

现象:本地正常接口访问,但是本地控制台打印乱码(本地环境编码格式为UTF-8),测试环境正常,控制台输出日志正常

最后判断,本地使用UTF-8编码格式,而发布环境是GBK编码格式,这样发送的请求会由于编码格式的问题产生乱码,导致mybatis-plus不能识别条件中的汉字而出错。

由于遗留问题,只能做这么多了,在本地测试的时候把控制台的编码格式换成UTF-8即可,发布到测试或者生产环境,已经做了标记,按需改变对应地方的编码格式即可,虽然可能麻烦点,却是成本最小的解决办法

接口因为编码不一致导致出错:org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Invalid UTF-8 middle byte 0x3f; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid UTF-8 middle byte 0x3f at [Source: (Pus Request","exception":"org. spring framework.http.converter.HttpMessageNotReadableException","message":" JSON parse error : Invalid UTF-8 mi ddl e byte 0x3f 我赶紧...
错误 提示 Invalid byte 1 of 1- byte UTF-8 sequence原因分析在中文版的window下 java 的默认的编码为GBK,也就是所虽然我们标识了要将xml保存为 utf-8 格式但实际上文件是以GBK格式来保存的,所以这也就是为什么能够我们使用GBK、GB2312编码来生成xml文件能正确的被解析,而以 UTF-8 格式生成的文件不能被xml解析器所解析的原因。 把xml的encoding属性值 UTF-8 改为UTF8org.xml.sax.SAX Parse Exception: Content is not allowed in trailing section把先要解析和字符
SoapUI 调用 CXF的restful形式接口服务异常:com.fasterxml.jackson.core. Json Parse Exception: Invalid UTF-8 start byt
2018-01-25 08:19:07,104 INFO  [org.apache.cxf.interceptor.LoggingInInterceptor] - Inbound Message ---------------------------- ID: 2 Address: http://localhost:8080/ibmp/ws/AppBankDevicesInfoRestSer
org. spring framework.http.converter.HttpMessageNotReadableException: JSON parse e rror: Invalid UTF-8 mi ddl e byte 0x3f ; nested exception is com.fasterxml.jackson. databind. Json MappingException: Invalid UT
au3反编译源码 myAut2Exe - The Open Source AutoIT Script Decompiler 2.9 ======================================================== *New* full support for AutoIT v3.2.6++ :) ... mmh here's what I merely mi ssed in the 'public sources 3.1.0' This program is for studying the 'Compiled' AutoIt3 format. AutoHotKey was developed from AutoIT and so scripts are nearly the same. Drag the compiled *.exe or *.a3x into the AutoIT Script Decompiler textbox. To copy text or to enlarge the log window double click on it. Supported Obfuscators: 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.14 [June 16, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.15 [July 1, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.20 [Sept 8, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.22 [Oct 18, 2007]' , 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.24 [Feb 15, 2008]' , 'EncodeIt 2.0' and 'Chr() string encode' Tested with: AutoIT : v3. 3. 0.0 and AutoIT : v2.64. 0.0 and AutoHotKey: v1.0.48.5 The options: =========== 'Force Old Script Type' Grey means auto detect and is the best in most cases. However if auto detection fails or is fooled through modification try to enable/disable this setting 'Don't delete temp files (compressed script)' this will keep *.pak files you may try to unpack manually with'LZSS.exe' as well as *.tok DeTokeniser files, tidy backups and *.tbl (<-Used in van Zande obfucation). If enable it will keep AHK-Scripts as they are and doesn't remove the linebreaks at the beginning Default:OFF 'Verbose LogOutput' When checked you get verbose information when decompiling(DeTokenise) new 3.2.6+ compiled Exe Default:OFF 'Restore Includes' will separated/restore includes. requires ';<AUT2EXE INCLUDE-START' comment to be present in the script to work Default:ON 'Use 'normal' Au3_Signature to find start of script' Will uses the normal 16- byte start signature to detect the start of a
Windows下RequestBody里中文格式 JSON 解析报错 大年29, 项目终于完工, 火急火燎的上线部署, 服务器是Windows系统, 项目框架是 Spring Boot2.2.11, 打成jar包运行后测试报错, 报错信息如下: JSON parse error : Invalid UTF-8 mi ddl e byte 0xe8; nested exception is com.fasterxml.jackson.databind. Json MappingException: Invalid U
这个 错误 是由于在解析 JSON 数据时遇到了无效的 UTF-8 字节 0x72 导致的。通常情况下, JSON 数据应该是有效的 UTF-8 编码,但这里遇到了一个无效的字节。 要解决这个 问题 ,你可以尝试以下几个步骤: 1. 确保输入的 JSON 数据是有效的 UTF-8 编码。可以使用其他工具或在线验证器来检查 JSON 数据的编码是否正确。 2. 如果你在客户端发送 JSON 数据到服务器,确保客户端正确地编码 JSON 数据为 UTF-8 。可以使用相应的库或方法来确保编码正确。 3. 如果你是在服务器端解析 JSON 数据,可以尝试检查请求头中的 Content-Type 是否正确设置为 application/ json ;charset= UTF-8 。 4. 检查你使用的 JSON 解析库是否支持 UTF-8 编码。有些库可能需要额外配置或处理来正确解析包含非标准字符的 JSON 数据。 如果以上步骤都没有解决 问题 ,你可以尝试查看更详细的 错误 日志或堆栈跟踪,以便更好地定位 问题 所在。