wcf - DataContractJsonSerializer and Enums -
When I serialize an enum value using DataContractJsonSerializer, it sorts numeric values of enum, No string name
IE:
enum foo {bar, baz} returns "0" to serialize the value of foo.bar No,
Edit:
Because I did not do this, want to change the serializer, I have used a simple workaround hack.
I have disclosed a property in the client, which makes toasting at the value of the call, i.e.:
// old [database] public EnumType Foo { Get {return _foo; } Set {_foo = value; }} // New, I still kept EnumType but only string version public EnumType Foo {get {return _foo; } Set {_foo = value; }} [DataMember] Public string FooType {get {return _foo.ToString ()}} Private set {}}
and this behavior can not be changed:
Calculation number values are considered as numbers in JSON, which differ from their behavior in data contracts, Where they are included as a member name.
Here's an example (and IMO better and more extensible) using the serializer that you are looking for:
using the system; Newton Soft. Jason's experiment; Classroom Program {Static Zero Main (string [] ARG) {var baz = Foo.Baz; Var serializer = new gene sensor (); Serializer.Converters.Add (New JsonEnumTypeConverter ()); Serializer.Serialize (Console.Out, baz); Console.WriteLine (); }} Enum Foo {Bar, False} Type the public class jsnime type: JsonConverter {Public Override Bull CanConvert (Type Object Type) {Type Object Type == (Foo); } Public override zero WriteJson (JasonSraft author, object value) {writer.WriteValue (Foo) value). Ostring ()); } Public Override Object ReadJson (JasonReader Reader, type object type) {return enum. Purse (typef (foo), reader vel. Toaster ()); }}
Comments
Post a Comment