当我试图用MockServer模拟外部HTTP时,mockserver返回java.lang.IllegalArgumentException
这是测试代码:
new MockServerClient("localhost", 1080)
.when(request("/messages")
.withMethod("POST")
.withQueryStringParameters(
param("subject", "integration-test-subject")
)
).respond(response().withStatusCode(200));这是一个例外:
java.lang.IllegalArgumentException: Exception while parsing
[
{
"httpRequest":{
"method":"POST",
"path":"/messages",
"queryStringParameters":{
"subject":[
"integration-test-subject"
]
}
},
"httpResponse":{
"statusCode":200
},
"times":{
"remainingTimes":0,
"unlimited":true
},
"timeToLive":{
"unlimited":true
}
}
] for Expectation这是杰克逊的例外:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of FIELD_NAME token
at
[
Source:(String)" {
"httpRequest":{
"method":"POST",
"path":"/messages",
"queryStringParameters":{
"subject":[
"integration-test-subject"
]
}
},
"httpResponse":{
"statusCode":200
},
"times":{
"remainingTimes":0,
"unlimited":true
},
"timeToLive":{
"unlimited":true
}
}我试着用body发送application/x-www-form-urlencoded请求
subject:integration-test-subject当.withQueryStringParameters(param("subject", "integration-test-subject"))不在测试中时,它就正常了。
怎么解决这个问题?
发布于 2018-04-02 10:49:38
解决此问题的方法是将以下内容添加到项目中:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.3</version>
</dependency>我的项目与Spring 2这个解决方案工作得很好。
发布于 2018-08-14 13:44:31
https://stackoverflow.com/questions/49298899
复制相似问题