From 2e47369b9ba40962078c5e1355c62bc7f301853f Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Tue, 8 Jul 2014 09:34:12 +0930 Subject: [PATCH] use opt-in attributes to indicate when a null property should be sent --- Octokit/Helpers/SerializeNullAttribute.cs | 9 +++++++++ Octokit/Http/SimpleJsonSerializer.cs | 16 ++++++++++++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 1 + Octokit/Octokit-Portable.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 8 files changed, 31 insertions(+) create mode 100644 Octokit/Helpers/SerializeNullAttribute.cs diff --git a/Octokit/Helpers/SerializeNullAttribute.cs b/Octokit/Helpers/SerializeNullAttribute.cs new file mode 100644 index 00000000..1716abc1 --- /dev/null +++ b/Octokit/Helpers/SerializeNullAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace Octokit.Internal +{ + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] + public sealed class SerializeNullAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index 789dba43..fb01c8d8 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Reflection; using Octokit.Reflection; namespace Octokit.Internal @@ -43,8 +44,23 @@ namespace Octokit.Internal { var value = getter.Value(input); if (value == null) + { continue; + // sometimes Octokit needs to send a null + // so look for this attribute when serializing + // XXX: we don't know which property we have at this point + // so this reflection trick doesn't work + + // TODO: make this magic work + //var property = type.GetProperty(getter.Key); + //var attribute = property.GetCustomAttribute(); + //if (attribute == null) + //{ + // continue; + //} + } + jsonObject.Add(MapClrMemberNameToJsonFieldName(getter.Key), value); } } diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index a5905eb4..e2a34b78 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -324,6 +324,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 42e54c8e..32316b15 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -334,6 +334,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index b7086e9a..57bed6ab 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -329,6 +329,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 1f9ecd6d..a0e014be 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -321,6 +321,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index d2344d30..a4fbbca9 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -325,6 +325,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 076c15bb..47539cbb 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -69,6 +69,7 @@ +