0

I just created an REST-ful webservice with a WebserviceHost. I have several methods that wil return a JSON-object to the user, if he makes a GET request.

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, 
    UriTemplate = "appliances/{username}")]
List<object[]> GetAvailableAppliances(string username);

This method returns values from a database. In the object-array are a few dbnull values but the standard JSON Serializer can't handle it. If the user does a request, the connection is resetted, but only if there are dbnull values in the list.

How can I handle these dbnull values? Do I have to change the values before the list will be serialized or is there a different solution?

Mossos
  • 97
  • 1
  • 11

1 Answers1

1

Personally I would never let a DBNull (which is, ultimately, an implementation detail) out past the data-access code; so yes, I would sanitize those at origin. null is usually an ideal substitute for DBNull outside of data-access code (although personally I'm of the opinion that DBNull shouldn't even exist). Treating everything as object isn't making it any clearer - if possible, some well-typed objects would also go a long way.

Community
  • 1
  • 1
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • 2
    Is there an easy way to do this or do I have to check every field in the table if there is a dbnull value? – Mossos Dec 12 '12 at 08:14