Update `IJsonHelper` to use `IHtmlContent`

- part of #3123 (2 of 5 or so)
- do not expose specific `HtmlString` class
This commit is contained in:
Doug Bunting 2015-11-23 16:44:33 -08:00
parent d84587a99d
commit 7bb0a1a4fe
2 changed files with 13 additions and 9 deletions

View File

@ -1,6 +1,7 @@
// 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.
using Microsoft.AspNet.Html.Abstractions;
using Newtonsoft.Json;
namespace Microsoft.AspNet.Mvc.Rendering
@ -14,15 +15,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Returns serialized JSON for the <paramref name="value"/>.
/// </summary>
/// <param name="value">The value to serialize as JSON.</param>
/// <returns>A new <see cref="HtmlString"/> containing the serialized JSON.</returns>
HtmlString Serialize(object value);
/// <returns>A new <see cref="IHtmlContent"/> containing the serialized JSON.</returns>
IHtmlContent Serialize(object value);
/// <summary>
/// Returns serialized JSON for the <paramref name="value"/>.
/// </summary>
/// <param name="value">The value to serialize as JSON.</param>
/// <param name="serializerSettings">The <see cref="JsonSerializerSettings"/> to be used by the serializer.</param>
/// <returns>A new <see cref="HtmlString"/> containing the serialized JSON.</returns>
HtmlString Serialize(object value, JsonSerializerSettings serializerSettings);
/// <param name="serializerSettings">
/// The <see cref="JsonSerializerSettings"/> to be used by the serializer.
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the serialized JSON.</returns>
IHtmlContent Serialize(object value, JsonSerializerSettings serializerSettings);
}
}

View File

@ -4,9 +4,10 @@
using System;
using System.Globalization;
using System.IO;
using Newtonsoft.Json;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Rendering;
using Newtonsoft.Json;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -32,13 +33,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public HtmlString Serialize(object value)
public IHtmlContent Serialize(object value)
{
return SerializeInternal(_jsonOutputFormatter, value);
}
/// <inheritdoc />
public HtmlString Serialize(object value, JsonSerializerSettings serializerSettings)
public IHtmlContent Serialize(object value, JsonSerializerSettings serializerSettings)
{
if (serializerSettings == null)
{
@ -50,7 +51,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return SerializeInternal(jsonOutputFormatter, value);
}
private HtmlString SerializeInternal(JsonOutputFormatter jsonOutputFormatter, object value)
private IHtmlContent SerializeInternal(JsonOutputFormatter jsonOutputFormatter, object value)
{
var stringWriter = new StringWriter(CultureInfo.InvariantCulture);
jsonOutputFormatter.WriteObject(stringWriter, value);