1

I am trying to create one mapping.json under the mappings folder with multiple stubs as below. But I am facing the following error

Wiremock: v2.5.1 (standalone)

Mapping.json file looks,

[
{
  "scenarioName": "Savings account Stub",
  "request": {
    "url": "/ws/*****",
    "method": "POST",
    "bodyPatterns" : [{
      "contains" : "AccountRequest"
    }
    ]
  },
  "response": {
    "status": 200,
    "bodyFileName": "******"
  }
},
{
  "scenarioName": "Current account Stub",
  "request": {
    "method": "POST",
    "url": "/ws/*****",
    "bodyPatterns": [
      {
        "contains": "AccountListRequest"
      }
    ]
  },
  "response": {
    "status": 200,
    "bodyFileName": "******"
  }
}]

Error:

Exception in thread "main" wiremock.com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.github.tomakehurst.wiremock.stubbing.StubMapping out of START_ARRAY token

Is there any possibility to create multiple stubs for the same URL in single mapping file? Can anyone tell me what is the exact issue?

1 Answers1

3

Looking at the stubbing documentation, I think you want your mappings.json to look like...

{ 
    "mappings": [
        {
            "scenarioName": "foo",
            "request": {},
            "response": {}
        }, {
            "request": {}
        }
    ],
    "importOptions": {
        "duplicatePolicy": "IGNORE",
        "deleteAllNotInImport": true
    }
}

You'd then want to make a POST request to /__admin/mappings/import with your mappings.json as the request body. The reason for this is that I believe multiple mappings in a single file are only supported via the import option.

agoff
  • 5,818
  • 1
  • 7
  • 20
  • Hi, @agoff I tried using **mappings**. When I start the wire mock I am facing **Mappings not a valid keyword(something like this)** and it displayed the valid keywords. I observed from google groups mappings got deleted in the latest versions. In v1+ it has support. – AnuragSanagapalli Apr 17 '20 at 04:55
  • Can you link to specifically what you mean by "mappings got deleted in the latest versions"? And apologies... The way that multiple mappings works requires it to be imported via the API, and not automatically pulled in when starting the server. I'll edit my response to indicate that. – agoff Apr 17 '20 at 13:31
  • Thanks, @agoff, and Apologies, It is not deleted but it won't support in a direct way. In my case, It won't possible for me to make a post request every time. Anyways, I have created individual stub files for each and I am able to use it. If there is any other way that can be done in a single file apart from this, please do let me know here. – AnuragSanagapalli Apr 17 '20 at 13:45
  • Why would you need to make a `POST` each time? Why couldn't you just have all of your mappings uploaded (either at start-up or through this initial POST)? – agoff Apr 20 '20 at 13:34