0

I'm having problems finding a simple way to force the built-in DataContractSerializer to serialize dictionaries in a simple format:

[{key1: value1}, {key2: value2}]

Instead, they are serialized as [{"Key": key1, "Value": value1}, ..]

Swapping out the default serializer with JSON.NET looks complex but I can find no global settings to tweak on the WCF DataContractSerializer.

I'm looking for something similar to the Web API global settings where I can say:

WcfDataContractSerializerGlobals.UseSimpleDictionaryFormat = true

I'm using a WebServiceHost in a unit test environment but don't see a way to inject a customized serializer in there, either.

Corey Alix
  • 2,694
  • 2
  • 27
  • 38
  • Have you seen https://stackoverflow.com/questions/7590088/make-asp-net-wcf-convert-dictionary-to-json-omitting-key-value-tags ? – Alex Seleznyov Nov 06 '17 at 22:25
  • @alex-seleznyov, Yes, I ended up switching to servicestack but before doing that modify all my contract methods to return a Message and explicitly serialized the response message using JSON.NET but then ran into routing limitations. It's too bad WCF isn't more REST friendly out-of-the-box. https://stackoverflow.com/questions/13659451/replace-default-json-serializer-in-wcf-4-to-json-net/13668979#13668979 – Corey Alix Nov 06 '17 at 22:45
  • One more solution which I'd use if I were in you position - https://stackoverflow.com/questions/33695058/wcf-service-parse-json-as-dictionarystring-string – Alex Seleznyov Nov 06 '17 at 22:50

0 Answers0