Skip to content

Commit

Permalink
Merge pull request #50 from ensembleVideo/issue-49
Browse files Browse the repository at this point in the history
Output is not using camel case
  • Loading branch information
samuelabj committed Feb 18, 2017
2 parents 5db542d + 94cb457 commit cc008f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Halcyon.Mvc/HAL/Json/JsonHalOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Primitives;

namespace Halcyon.Web.HAL.Json {
public class JsonHalOutputFormatter : IOutputFormatter {
public const string HalJsonType = "application/hal+json";

private readonly IEnumerable<string> halJsonMediaTypes;
private readonly JsonOutputFormatter jsonFormatter;
private readonly JsonSerializerSettings serializerSettings;


public JsonHalOutputFormatter(IEnumerable<string> halJsonMediaTypes = null) {
if(halJsonMediaTypes == null) halJsonMediaTypes = new string[] { HalJsonType };

var serializerSettings = JsonSerializerSettingsProvider.CreateSerializerSettings();
this.serializerSettings = JsonSerializerSettingsProvider.CreateSerializerSettings();

this.jsonFormatter = new JsonOutputFormatter(serializerSettings, ArrayPool<Char>.Create());
this.jsonFormatter = new JsonOutputFormatter(this.serializerSettings, ArrayPool<Char>.Create());

this.halJsonMediaTypes = halJsonMediaTypes;
}
Expand All @@ -45,7 +47,7 @@ public class JsonHalOutputFormatter : IOutputFormatter {
var halResponse = ((HALResponse)context.Object);

// If it is a HAL response but set to application/json - convert to a plain response
var serializer = JsonSerializer.Create();
var serializer = JsonSerializer.Create(this.serializerSettings);

if(!halResponse.Config.ForceHAL && !halJsonMediaTypes.Contains(mediaType)) {
value = halResponse.ToPlainResponse(serializer);
Expand Down
3 changes: 2 additions & 1 deletion test/Halcyon.Tests.SelfHost.Mvc/Controllers/FooController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class FooController : Controller {
// Any plain old object will do
var fooModel = new {
id,
type = "foo"
type = "foo",
CamelCase = "this should be camelCase"
};

// Return a simple resource with links to related resources
Expand Down

0 comments on commit cc008f5

Please sign in to comment.