1

I have a WEB API that returns null data sometimes. I am expecting the below format as response

{"cardResponse" : null}

but I am getting {} as response. Any Idea?

My method Definition looks like:

public HttpResponseMessage Opeation(string input1, [FromUri] input2 request)

The return statement looks like :

return Request.CreateResponse(HttpStatusCode.OK, response);

Response Class Structure:

public class RootResponse    {

    public CardResponse cardResponse{ get; set; }

}

  Public class CardResponse  {

    public string CardName { get ; set;}  
}
3
  • Which type is it response ? Commented Jan 25, 2017 at 15:20
  • 1
    Not an ASP expert here, but I'm pretty sure you'll need to post more code. What's the value of response in the last snippet? Show the code around that line Commented Jan 25, 2017 at 15:20
  • @OrelEraki Edited the Question. Added the response Class Commented Jan 25, 2017 at 15:30

1 Answer 1

1

You have NullValueHandling option set to NullValueHandling.Ignore in your JSON formatter. Check WebApiConfig if there is default formatter replaced or someone could turn-off null values passing for default JsonMediaTypeFormatter.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow. Thanks alot :) Seems I have added that line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.