Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ internal static JsonSerializerSettings DefaultSerializerSettings(ApiRequestor re
new StripeObjectConverter(),
},
DateParseHandling = DateParseHandling.None,
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
MaxDepth = 128,
};
}
Expand Down
23 changes: 21 additions & 2 deletions src/StripeTests/Entities/_base/StripeEntityTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace StripeTests
{
using System;
using System.Collections.Generic;
using System.Globalization;

using Newtonsoft.Json;
Expand Down Expand Up @@ -72,18 +73,33 @@ public void FromJsonGeneric()
Assert.Equal("String!", o.String);
}

[Fact]
public void FromJsonDollarRefInMetadata()
{
var json = "{\"integer\": 234, \"string\": \"String!\", \"metadata\": { \"$ref\": \"1\", \"foo\": \"bar\" }}";

var o = StripeEntity.FromJson<TestEntity>(json);

Assert.NotNull(o);
Assert.Equal(234, o.Integer);
Assert.Equal("String!", o.String);
Assert.Equal("1", o.Metadata["$ref"]);
Assert.Equal("bar", o.Metadata["foo"]);
}

[Fact]
public void ToJson()
{
var o = new TestEntity
{
Integer = 234,
String = "String!",
Metadata = new Dictionary<string, string>() { { "foo", "bar" } },
};

var json = o.ToJson().Replace("\r\n", "\n");

var expectedJson = "{\n \"integer\": 234,\n \"string\": \"String!\",\n \"nested\": null\n}";
var expectedJson = "{\n \"integer\": 234,\n \"string\": \"String!\",\n \"metadata\": {\n \"foo\": \"bar\"\n },\n \"nested\": null\n}";
Assert.Equal(expectedJson, json);
}

Expand Down Expand Up @@ -181,14 +197,17 @@ public void RawJObject()
subscription.RawJObject["items"]["data"][0]["id"]);
}

private class TestEntity : StripeEntity<TestEntity>
private class TestEntity : StripeEntity<TestEntity>, IHasMetadata
{
[JsonProperty("integer")]
public int Integer { get; set; }

[JsonProperty("string")]
public string String { get; set; }

[JsonProperty("metadata")]
public Dictionary<string, string> Metadata { get; set; }

[JsonIgnore]
public string NestedId
{
Expand Down
Loading