Forum Discussion

JustinM89's avatar
JustinM89
Contributor
9 years ago

Null values in JSON passed as { }

I have a JSON request I am sending, and it contains many keys with a null value. Somehow, during the transfer of this JSON to my request (or when it is sent), any null values are all magically switched over to { }, and I get a 400 error because the server is expecting literal nulls. I've tried looking and poking around and cannot find any kind of setting within SoapUI to prevent this.

 

There is a workaround in that the request still goes through if I remove any JSON nodes with a null value, the problem is that there's 180 of them, and that's kind of a hefty workaround for what I assume would be a simple task. Can anyone offer any insight into this?

 

TL;DR: My JSON request has many keys with a literal null value, but when the JSON is transferred to the request, all the nulls switch to { } and my request fails.

  • We actually managed to make it work, but we're not sure why it works this way and why it doesn't work the other way.

     

    My transfer step actually has 3 transfers, in this order:

    1. requestJSON - The entire JSON request body (the one with all the nulls)
    2. reportId- Set to a specific node in requestJSON
    3. invoiceType - Also set to a specific node in requestJSON

    Executing the request like this, all of the null values get switched to { }. However, when we move requestJSON to the bottom of the transfers (so the last one to get transferred), it keeps the nulls. For some reason the order of these property transfers affects the JSON. Is this a bug?

     

    To get around this, we just used a Groovy script to inject the reportId and invoiceType directly into requestJSON, so we only need to transfer requestJSON instead of all 3.

    • JustinM89's avatar
      JustinM89
      Contributor

      Yes, this is a POST, and what's even weirder is that I have a different test case that has nulls, and when I POST that request, it sends the literal nulls; they don't get switched to { }. I've pored over that test case to see what I did differently and can't find anything.

       

      The way this works is, I hit various endpoints which return JSON. I assign this JSON to a custom property, use Groovy scripts to manipulate it (removing unecessary parts and things like that), then assign it back to the custom property. Lastly, I transfer my formatted JSON from the custom property to the request.

       

      I've attached a screenshot of the JSON. On the right is a picture of the JSON copied/pasted directly from the custom property. On the left is the same snippet of JSON, but from the actual request, and you can see the difference in values.

      • JustinM89's avatar
        JustinM89
        Contributor

        We actually managed to make it work, but we're not sure why it works this way and why it doesn't work the other way.

         

        My transfer step actually has 3 transfers, in this order:

        1. requestJSON - The entire JSON request body (the one with all the nulls)
        2. reportId- Set to a specific node in requestJSON
        3. invoiceType - Also set to a specific node in requestJSON

        Executing the request like this, all of the null values get switched to { }. However, when we move requestJSON to the bottom of the transfers (so the last one to get transferred), it keeps the nulls. For some reason the order of these property transfers affects the JSON. Is this a bug?

         

        To get around this, we just used a Groovy script to inject the reportId and invoiceType directly into requestJSON, so we only need to transfer requestJSON instead of all 3.