Problem with json input

I’m having an annoying problem with the json input of requests. It’s somewhat hard to describe and I’m neither a code wizard nor english native speaker, but I hope the screenshots below will make it clear. The problem in a nutshell is that more often than not the json body I pass in the request ends up empty.

Case 1: I click on the model schema in the swagger ui to set it as parameter value in the body (see screenshot 1), where I edit the parameters, then I copy the body in “LoginUser” and try it out. That almost always works wonderful. The “PatchUsr” request parameter in the procedure (screenshot 2) has all the data from the LoginUser body.

Case 2: but if I then copy for instance the body in a text editor (notepad++) and edit the parameters there, and copy the text from the text editor into “LoginUser”, the object passed as parameter in “PatchUsr” is completely empty (ie all fields empty), even though I can’t imagine what could be different. Same thing if I pass it outside of the swagger ui programmatically.

How can this input be so sensitive? And what could be the cause?

image

If it’s empty it’s typically because the JSON that’s sent does not match the schema of the Request DTO you’re trying to send (& deserialize) it to. You also can’t send both a form and body request, any additional params would need to be part of your Route or querystring.

You can view the expected JSON of the Request DTO by populating at serializing it, e.g:

var dto = new PatchUsr { ... };
var json = dto.ToJson();
json.Print();

Which you could then send with the JsonServiceClient, e.g:

var client = new JsonServiceClient(baseUrl);
var response = client.Post(new PatchUsr { ... });