Remove derivation based extensibility points.
This commit is contained in:
parent
764e5f890d
commit
9365004248
|
|
@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
private readonly object _returnValue;
|
||||
|
||||
private JsonSerializerSettings _jsonSerializerSettings;
|
||||
private Encoding _encoding;
|
||||
private Encoding _encoding = Encoding.UTF8;
|
||||
|
||||
public JsonResult(object returnValue)
|
||||
{
|
||||
|
|
@ -21,8 +21,6 @@ namespace Microsoft.AspNet.Mvc
|
|||
throw new ArgumentNullException("returnValue");
|
||||
}
|
||||
|
||||
Encoding = Encoding.UTF8;
|
||||
|
||||
_returnValue = returnValue;
|
||||
_jsonSerializerSettings = CreateSerializerSettings();
|
||||
}
|
||||
|
|
@ -61,43 +59,16 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
}
|
||||
|
||||
public virtual JsonSerializerSettings CreateSerializerSettings()
|
||||
{
|
||||
return new JsonSerializerSettings()
|
||||
{
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||
|
||||
// Do not change this setting
|
||||
// Setting this to None prevents Json.NET from loading malicious, unsafe, or security-sensitive types.
|
||||
TypeNameHandling = TypeNameHandling.None
|
||||
};
|
||||
}
|
||||
|
||||
public virtual JsonSerializer CreateJsonSerializer()
|
||||
{
|
||||
JsonSerializer jsonSerializer = JsonSerializer.Create(SerializerSettings);
|
||||
|
||||
return jsonSerializer;
|
||||
}
|
||||
|
||||
public virtual JsonWriter CreateJsonWriter(Stream writeStream, Encoding effectiveEncoding)
|
||||
{
|
||||
JsonWriter jsonWriter = new JsonTextWriter(new StreamWriter(writeStream, effectiveEncoding));
|
||||
if (Indent)
|
||||
{
|
||||
jsonWriter.Formatting = Formatting.Indented;
|
||||
}
|
||||
|
||||
return jsonWriter;
|
||||
}
|
||||
|
||||
public async Task ExecuteResultAsync(RequestContext context)
|
||||
{
|
||||
HttpResponse response = context.HttpContext.Response;
|
||||
|
||||
Stream writeStream = response.Body;
|
||||
|
||||
response.ContentType = "application/json";
|
||||
if (response.ContentType == null)
|
||||
{
|
||||
response.ContentType = "application/json";
|
||||
}
|
||||
|
||||
using (JsonWriter jsonWriter = CreateJsonWriter(writeStream, Encoding))
|
||||
{
|
||||
|
|
@ -109,5 +80,35 @@ namespace Microsoft.AspNet.Mvc
|
|||
jsonWriter.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
private JsonSerializerSettings CreateSerializerSettings()
|
||||
{
|
||||
return new JsonSerializerSettings()
|
||||
{
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||
|
||||
// Do not change this setting
|
||||
// Setting this to None prevents Json.NET from loading malicious, unsafe, or security-sensitive types.
|
||||
TypeNameHandling = TypeNameHandling.None
|
||||
};
|
||||
}
|
||||
|
||||
private JsonSerializer CreateJsonSerializer()
|
||||
{
|
||||
JsonSerializer jsonSerializer = JsonSerializer.Create(SerializerSettings);
|
||||
|
||||
return jsonSerializer;
|
||||
}
|
||||
|
||||
private JsonWriter CreateJsonWriter(Stream writeStream, Encoding effectiveEncoding)
|
||||
{
|
||||
JsonWriter jsonWriter = new JsonTextWriter(new StreamWriter(writeStream, effectiveEncoding));
|
||||
if (Indent)
|
||||
{
|
||||
jsonWriter.Formatting = Formatting.Indented;
|
||||
}
|
||||
|
||||
return jsonWriter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue