wiremock返回json格式数据,服务器解析失败

服务器报错日志如下:

Caused by: feign.codec.DecodeException: Error while extracting response for type [class com.sunyard.sany.ccb.resp.BusinessStatusResp] and content type [application/json;charset=utf-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens

通过比对发现,wiremock会自动在heard头添加如下参数

'Matched-Stub-Id': 'da9ac487-02e8-4ef1-ba4b-9bfe01c68504', 'Vary': 'Accept-Encoding, User-Agent', 'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked'

引起报错的正是: 'Content-Encoding': 'gzip'

服务器不改代码,能正确解析的写法

{

        "request":{

                "urlPattern":"/test/status.*",

                "bodyPatterns":[{"matchesJsonPath":"$[?(@.test== 'ttttt')]"}]

        },

        "response":{

                "status":200,

                "jsonBody" : {

                                "code": "0",

                                "message": "成功",

                                "status": "2"

                        },

                "headers" : {

                        "Content-Type" : "application/json;charset=utf-8",

                        "Content-Encoding":""

                }

        }

}

解决过程中,看到的其他解决办法(未验证)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。