I have the following class:
[Serializable]
public class ApiRequestStatus :IEquatable<ApiRequestStatus>
{
public static readonly ApiRequestStatus Failure =
new ApiRequestStatus("Failure");
public static readonly ApiRequestStatus Success =
new ApiRequestStatus("Success");
private string _status;
private ApiRequestStatus(string status)
{
this._status = status;
}
public override string ToString()
{
return _status;
}
public bool Equals(ApiRequestStatus other)
{
return this._status == other._status;
}
}
When this is serialized using the
I would like it to serialize as either the string System.Web.Script.Serialization.JavaScriptSerializer
"Failure"
or "Success"
.
I have attempted to create a custom JavaScriptConverter
, but this results in my object being rendered with zero or more properties depending on the
IDictionary<string, object>
I return.
For example, when I return an empty
IDictionary<string, object>
, my object appears as an empty JavaScript object: { }
.
If I return
new Dictionary<string, object> { {"_status", status._status}}
, my object appears as { "_status" : "Success" }
.
How can I serialize the object to only include the string value of its _status
field?