Made JsonOutputFormatter consistent with JsonInputFormatter

This commit is contained in:
Ajay Bhargav Baaskaran 2015-06-22 11:17:06 -07:00
parent f206cf6759
commit 4a4b8ec87e
2 changed files with 17 additions and 17 deletions

View File

@ -101,9 +101,10 @@ namespace Microsoft.AspNet.Mvc
/// <param name="readStream">The <see cref="Stream"/> from which to read.</param> /// <param name="readStream">The <see cref="Stream"/> from which to read.</param>
/// <param name="effectiveEncoding">The <see cref="Encoding"/> to use when reading.</param> /// <param name="effectiveEncoding">The <see cref="Encoding"/> to use when reading.</param>
/// <returns>The <see cref="JsonReader"/> used during deserialization.</returns> /// <returns>The <see cref="JsonReader"/> used during deserialization.</returns>
public virtual JsonReader CreateJsonReader([NotNull] InputFormatterContext context, protected virtual JsonReader CreateJsonReader(
[NotNull] Stream readStream, [NotNull] InputFormatterContext context,
[NotNull] Encoding effectiveEncoding) [NotNull] Stream readStream,
[NotNull] Encoding effectiveEncoding)
{ {
return new JsonTextReader(new StreamReader(readStream, effectiveEncoding)); return new JsonTextReader(new StreamReader(readStream, effectiveEncoding));
} }
@ -112,7 +113,7 @@ namespace Microsoft.AspNet.Mvc
/// Called during deserialization to get the <see cref="JsonSerializer"/>. /// Called during deserialization to get the <see cref="JsonSerializer"/>.
/// </summary> /// </summary>
/// <returns>The <see cref="JsonSerializer"/> used during serialization and deserialization.</returns> /// <returns>The <see cref="JsonSerializer"/> used during serialization and deserialization.</returns>
public virtual JsonSerializer CreateJsonSerializer() protected virtual JsonSerializer CreateJsonSerializer()
{ {
return JsonSerializer.Create(SerializerSettings); return JsonSerializer.Create(SerializerSettings);
} }

View File

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Internal;
@ -14,14 +13,6 @@ namespace Microsoft.AspNet.Mvc
/// <summary> /// <summary>
/// An output formatter that specializes in writing JSON content. /// An output formatter that specializes in writing JSON content.
/// </summary> /// </summary>
/// <remarks>
/// The <see cref="JsonResult"/> class filter the collection of
/// <see cref="MvcOptions.OutputFormatters"/> and use only those of type
/// <see cref="JsonOutputFormatter"/>.
///
/// To create a custom formatter that can be used by <see cref="JsonResult"/>, derive from
/// <see cref="JsonOutputFormatter"/>.
/// </remarks>
public class JsonOutputFormatter : OutputFormatter public class JsonOutputFormatter : OutputFormatter
{ {
private JsonSerializerSettings _serializerSettings; private JsonSerializerSettings _serializerSettings;
@ -66,7 +57,12 @@ namespace Microsoft.AspNet.Mvc
} }
} }
private JsonWriter CreateJsonWriter(TextWriter writer) /// <summary>
/// Called during serialization to create the <see cref="JsonWriter"/>.
/// </summary>
/// <param name="writer">The <see cref="TextWriter"/> used to write.</param>
/// <returns>The <see cref="JsonWriter"/> used during serialization.</returns>
protected virtual JsonWriter CreateJsonWriter([NotNull] TextWriter writer)
{ {
var jsonWriter = new JsonTextWriter(writer); var jsonWriter = new JsonTextWriter(writer);
jsonWriter.CloseOutput = false; jsonWriter.CloseOutput = false;
@ -74,10 +70,13 @@ namespace Microsoft.AspNet.Mvc
return jsonWriter; return jsonWriter;
} }
private JsonSerializer CreateJsonSerializer() /// <summary>
/// Called during serialization to create the <see cref="JsonSerializer"/>.
/// </summary>
/// <returns>The <see cref="JsonSerializer"/> used during serialization and deserialization.</returns>
protected virtual JsonSerializer CreateJsonSerializer()
{ {
var jsonSerializer = JsonSerializer.Create(_serializerSettings); return JsonSerializer.Create(SerializerSettings);
return jsonSerializer;
} }
public override Task WriteResponseBodyAsync(OutputFormatterContext context) public override Task WriteResponseBodyAsync(OutputFormatterContext context)