tags:

views:

90

answers:

1

Microsoft reports that Enumeration member values are treated as numbers in JSON.

We're building the WebMethod output into a table by hand, so converting the member number into it's name on the client is possible, but it smells and would be less robust than converting it on the server, using Enum.GetName. For example, if we add or change the enumeration it would mean changing our Javascript.

Is there an (easy) way to do this in the WebMethod? The object serializes correctly, and was working when we were using XML to transport the result.

+1  A: 

If you just need to display it on the client, I'd add an extra string-typed property getter to your wire entity that does the Enum.GetName call. If it has to round-trip, you could add a setter on the same property that parses the enum value.

Kinda nasty, but not as bad as hardcoding a list on the client...

nitzmahone
+1 We're on .NET 3.5 so I can use an anonymous type to add the extra property (we're not using a DTO). Not ideal but agree it's better than doing it on the client.
Si