5

When i'm trying to mock external HTTP API with MockServer, mockserver returns java.lang.IllegalArgumentException

This is the test code:

new MockServerClient("localhost", 1080)
    .when(request("/messages")
    .withMethod("POST")
    .withQueryStringParameters(
        param("subject", "integration-test-subject")
    )
).respond(response().withStatusCode(200));

This is the exception:

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

And this is the Jackson exception:

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
      }
   }

I'm trying to send application/x-www-form-urlencoded request with body

subject:integration-test-subject

When .withQueryStringParameters(param("subject", "integration-test-subject")) is not present in test, then it goes OK.

How to fix this?

xsami
  • 1,312
  • 16
  • 31
Igor
  • 478
  • 9
  • 22
  • any solution yet? it seems that some deserializer for MultiValueMap is not registered in jackson. I have the same problem, but with headers. – Patryk Dobrowolski Mar 30 '18 at 11:10
  • @PatrykDobrowolski i haven't tested yet, but looks like you should downgrade jackson to com.fasterxml.jackson.core:jackson-databind:2.9.3 – Igor Apr 02 '18 at 09:44

2 Answers2

2

This is an issue in GitHub with an explanation

https://github.com/jamesdbloom/mockserver/issues/451

you can just update to 5.4.1

lanwen
  • 2,251
  • 1
  • 17
  • 30
1

the solution of this problem is to add to your project:

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.3</version>
    </dependency>

im my project with Spring Boot 2 this solution worked fine.

Igor
  • 478
  • 9
  • 22