1

i am wondering if there is a way to prevent a response to return keys in object that are null or null equivalent. I have for example a Response envelope and then the data payload and a sample response looks like this.

{
    "success": true,
    "errorCode": "",
    "message": "JWT Token succesfull created",
    "data": {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoidXNlcmlkIiwiU2NvcGUiOlsiQVRUQ1NSIiwiQVRUTFNSIl0sIm5iZiI6MTU4NDc0MjIzMiwiZXhwIjoxNTg0NzQzOTcyLCJpc3MiOiJodHRwOi8vc29hcGFwaS5wZ3RlbC5uZXQiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjU3NDY0In0.dWuETKdlfX4VzwWEP5XafZOpnFmSSCchQHUHi5GZ99E",
        "expiration": "0001-01-01T00:00:00",
        "scope": null
    }
}

In this case expiration and scope are null expiration is a DateTime field.

Here is how i get to this response

 Dim myResponse As New jsonResponse
     myResponse.success = True
     meResponse.errorCode = ""
     myResponse.message = "JWT Token succesfull created"
 Dim authCheck As New JSONWebTokenUtil
 Dim accessList As New List(Of String)
     accessList.Add("Sample1")
 Dim Token = authCheck.GenerateJSONWebToken("userid", accessList, )

 Dim myToken As New tokenResponse
     myToken.token = Token
     myResponse.data = myToken
 Return myResponse

So since in the above case i dont set the scope or experation its null. Is there a way to be part of the out put if null or do i need to check each value and remove it if its null

NoSoup4you
  • 640
  • 1
  • 10
  • 34
  • 1
    Does [How to ignore a property in class if null, using json.net](https://stackoverflow.com/questions/6507889/how-to-ignore-a-property-in-class-if-null-using-json-net) help? (P.S. the spelling is "expiration".) – Andrew Morton Mar 22 '20 at 16:55

1 Answers1

-1

I would try the following, from vb.net when you recive the json response, add the response to a string variable the with the replace's string method try to change the null value to a new value. I hope this be useful. Thank you. :)

I3efIzzgsw
  • 85
  • 1
  • 1
  • 7