mockserver icon indicating copy to clipboard operation
mockserver copied to clipboard

Body Type

Open OptimistNot opened this issue 9 years ago • 2 comments

Hello guys! I think I found a little problem… if you create an object that originate JSON with first key named "type", like this: MyObject(@JsonParameter("type") String type, @JsonParameter("any") int any) {} and it's JSON: {type:“StringValue”, any:1} and use something like this to verify request with MyObject inside a body:

        myClient.verify(HttpRequest.request()
                        .withMethod("POST")
                        .withPath(INDEX)
                        .withBody(new RegexBody("my regex matching "any" key and it's value"))),
                VerificationTimes.exactly(1));

it will give you warning: ObjectMapperFactory - Ignoring invalid value for "type" field of "StringValue". I think this happens because body's first key "type" is interpreted to know what type of body was used. From your docs:

  {
       "type": <"STRING" or "REGEX" or "JSON" or "JSON_SCHEMA" or "XPATH" or "PARAMETERS">,
       "value": "" ( or "parameters" as shown in more detail below )
    }

Maybe you should check if it's inside a "value" first to avoid this ambiguity. It's not a big problem, I just renamed my key, but still it doesn't feel right. Thank you! Best regards

OptimistNot avatar May 24 '17 17:05 OptimistNot

I'll take a look as this sounds like something that should be fixed.

jamesdbloom avatar Jun 15 '17 11:06 jamesdbloom

It looks like this can't be fully resolved for complex reasons, however this message is misleading and confusing because it is fully handled correctly. I reduce the log level of this message to debug and so I'm going to close this ticket.

jamesdbloom avatar Jun 15 '17 12:06 jamesdbloom