From cb1fa30e6d3bfbae4f2ad86cb1cccdec55f38b8a Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Mon, 22 Jan 2018 11:52:15 +0900 Subject: [PATCH 01/12] add more test for #39 --- tests/Utf8Json.Tests/JsonReaderWriterTest.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Utf8Json.Tests/JsonReaderWriterTest.cs b/tests/Utf8Json.Tests/JsonReaderWriterTest.cs index 3795033..e94e005 100644 --- a/tests/Utf8Json.Tests/JsonReaderWriterTest.cs +++ b/tests/Utf8Json.Tests/JsonReaderWriterTest.cs @@ -216,5 +216,17 @@ public void LargeString2() aaa.Is(origstr); } + + [Fact] + public void LargeString3() + { + var origstr = new string('a', 999999); + var str = "\"" + origstr + "\""; + + var reader = new JsonReader(Encoding.UTF8.GetBytes(str), 0); + var aaa = reader.ReadString(); + + aaa.Is(origstr); + } } } From 3e7c6c4af5fd662d68975bcabc3f66c89d4bf45c Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Mon, 22 Jan 2018 16:07:56 +0900 Subject: [PATCH 02/12] fix #39 --- src/Utf8Json/JsonReader.cs | 4 ++-- tests/Utf8Json.Tests/JsonReaderWriterTest.cs | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Utf8Json/JsonReader.cs b/src/Utf8Json/JsonReader.cs index e60e428..e0117ff 100644 --- a/src/Utf8Json/JsonReader.cs +++ b/src/Utf8Json/JsonReader.cs @@ -599,7 +599,7 @@ void ReadStringSegmentCore(out byte[] resultBytes, out int resultOffset, out int if (builder == null) builder = StringBuilderCache.GetBuffer(); var copyCount = i - from; - BinaryUtil.EnsureCapacity(ref builder, builderOffset, copyCount); + BinaryUtil.EnsureCapacity(ref builder, builderOffset, copyCount + 1); // require + 1 Buffer.BlockCopy(bytes, from, builder, builderOffset, copyCount); builderOffset += copyCount; } @@ -648,7 +648,7 @@ void ReadStringSegmentCore(out byte[] resultBytes, out int resultOffset, out int } var copyCount = i - from; - BinaryUtil.EnsureCapacity(ref builder, builderOffset, copyCount); + BinaryUtil.EnsureCapacity(ref builder, builderOffset, copyCount + 1); // require + 1! Buffer.BlockCopy(bytes, from, builder, builderOffset, copyCount); builderOffset += copyCount; builder[builderOffset++] = escapeCharacter; diff --git a/tests/Utf8Json.Tests/JsonReaderWriterTest.cs b/tests/Utf8Json.Tests/JsonReaderWriterTest.cs index e94e005..8b46f15 100644 --- a/tests/Utf8Json.Tests/JsonReaderWriterTest.cs +++ b/tests/Utf8Json.Tests/JsonReaderWriterTest.cs @@ -228,5 +228,15 @@ public void LargeString3() aaa.Is(origstr); } + + [Fact] + public void LargeString4() + { + var origstr = new string('a', 999999); + var str = "\"" + origstr + "\""; + + var serialized = JsonSerializer.Serialize(str); + var deserialized = JsonSerializer.Deserialize(serialized); + } } } From 87c62d399dc64c4eafd815c6a69f44c4bd697ee7 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Mon, 22 Jan 2018 20:38:10 +0900 Subject: [PATCH 03/12] exception serialization support config(nameMutate, excludeNull) and serialize public members. #41 --- sandbox/ConsoleAppNetCore/Program.cs | 14 ++- sandbox/DynamicCodeDumper/Program.cs | 12 ++- src/Utf8Json/Formatters/ExceptionFormatter.cs | 51 ---------- src/Utf8Json/Internal/Emit/MetaMember.cs | 94 ++++++++++++++++--- src/Utf8Json/Internal/Emit/MetaType.cs | 6 +- src/Utf8Json/JsonSerializer.NonGeneric.cs | 13 +++ .../Resolvers/DynamicGenericResolver.cs | 5 - .../Resolvers/DynamicObjectResolver.cs | 60 ++++++++++-- tests/Utf8Json.Tests/ExceptionTest.cs | 41 ++++++-- 9 files changed, 197 insertions(+), 99 deletions(-) delete mode 100644 src/Utf8Json/Formatters/ExceptionFormatter.cs diff --git a/sandbox/ConsoleAppNetCore/Program.cs b/sandbox/ConsoleAppNetCore/Program.cs index b9f4830..5f8761a 100644 --- a/sandbox/ConsoleAppNetCore/Program.cs +++ b/sandbox/ConsoleAppNetCore/Program.cs @@ -334,11 +334,17 @@ public void SetId(Guid id) static unsafe void Main(string[] args) { + try + { + throw new Exception("ABC", new FooException { Bar = 100 }); + } + catch (Exception ex) + { + var json = JsonSerializer.ToJsonString(ex, Utf8Json.Resolvers.StandardResolver.Default); + Console.WriteLine(JsonSerializer.PrettyPrint(json)); - var ex = new Exception("ABC", new FooException { Bar = 100 }); - var json = JsonSerializer.ToJsonString(ex); - Console.WriteLine(JsonSerializer.PrettyPrint(json)); - + //Console.WriteLine(json); + } } static (int, int[]) Array(int[] xs) diff --git a/sandbox/DynamicCodeDumper/Program.cs b/sandbox/DynamicCodeDumper/Program.cs index dae851c..a8fa2e5 100644 --- a/sandbox/DynamicCodeDumper/Program.cs +++ b/sandbox/DynamicCodeDumper/Program.cs @@ -21,11 +21,13 @@ static void Main(string[] args) //DynamicObjectResolver.Default.GetFormatter(); //DynamicObjectResolver.ExcludeNullCamelCase.GetFormatter(); - var seq = Enumerable.Range(1, 10).Select(x => x); - DynamicObjectResolver.Default.GetFormatterDynamic(seq.GetType()); + //var seq = Enumerable.Range(1, 10).Select(x => x); + //DynamicObjectResolver.Default.GetFormatterDynamic(seq.GetType()); - var yahhoi = CompositeResolver.Create(new IJsonFormatter[0], new[] { StandardResolver.Default }); + //var yahhoi = CompositeResolver.Create(new IJsonFormatter[0], new[] { StandardResolver.Default }); + + DynamicObjectResolver.ExcludeNull.GetFormatter(); //DynamicObjectResolver.Default.GetFormatter(); //DynamicObjectResolver.Default.GetFormatter(); @@ -50,13 +52,13 @@ static void Main(string[] args) #if NET45 var a1 = (DynamicObjectResolver.Default as ISave).Save(); - var a2 = (DynamicObjectResolver.ExcludeNullCamelCase as ISave).Save(); + var a2 = (DynamicObjectResolver.ExcludeNull as ISave).Save(); //var a2 = DynamicUnionResolver.Instance.Save(); //var a3 = DynamicEnumResolver.Instance.Save(); //var a4 = DynamicContractlessObjectResolver.Instance.Save(); var a3 = DynamicCompositeResolver.Save(); - Verify(a3); + Verify(a2); #endif } } diff --git a/src/Utf8Json/Formatters/ExceptionFormatter.cs b/src/Utf8Json/Formatters/ExceptionFormatter.cs deleted file mode 100644 index a36d62c..0000000 --- a/src/Utf8Json/Formatters/ExceptionFormatter.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; - -namespace Utf8Json.Formatters -{ - public class ExceptionFormatter : IJsonFormatter - where TException : Exception - { - static readonly byte[] classNamePropertyName; - static readonly byte[] messagePropertyName; - static readonly byte[] sourcePropertyName; - static readonly byte[] stackTracePropertyName; - static readonly byte[] innerExceptionPropertyName; - - static ExceptionFormatter() - { - classNamePropertyName = JsonWriter.GetEncodedPropertyNameWithBeginObject("ClassName"); - messagePropertyName = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator("Message"); - sourcePropertyName = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator("Source"); - stackTracePropertyName = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator("StackTrace"); - innerExceptionPropertyName = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator("InnerException"); - } - - public void Serialize(ref JsonWriter writer, TException value, IJsonFormatterResolver formatterResolver) - { - writer.WriteRaw(classNamePropertyName); - writer.WriteString(value.GetType().FullName); - - writer.WriteRaw(messagePropertyName); - writer.WriteString(value.Message); - - writer.WriteRaw(sourcePropertyName); - writer.WriteString(value.Source); - - writer.WriteRaw(stackTracePropertyName); - writer.WriteString(value.StackTrace); - - if (value.InnerException != null) - { - writer.WriteRaw(innerExceptionPropertyName); - formatterResolver.GetFormatter().Serialize(ref writer, value.InnerException, formatterResolver); - } - - writer.WriteEndObject(); - } - - public TException Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) - { - throw new NotSupportedException("Exception formatter does not support deserialize."); - } - } -} \ No newline at end of file diff --git a/src/Utf8Json/Internal/Emit/MetaMember.cs b/src/Utf8Json/Internal/Emit/MetaMember.cs index feda606..4ad3a9b 100644 --- a/src/Utf8Json/Internal/Emit/MetaMember.cs +++ b/src/Utf8Json/Internal/Emit/MetaMember.cs @@ -17,7 +17,7 @@ internal class MetaMember public bool IsField { get { return FieldInfo != null; } } public bool IsWritable { get; private set; } public bool IsReadable { get; private set; } - public Type Type { get { return IsField ? FieldInfo.FieldType : PropertyInfo.PropertyType; } } + public Type Type { get; private set; } public FieldInfo FieldInfo { get; private set; } public PropertyInfo PropertyInfo { get; private set; } public MethodInfo ShouldSerializeMethodInfo { get; private set; } @@ -25,11 +25,21 @@ internal class MetaMember MethodInfo getMethod; MethodInfo setMethod; + protected MetaMember(Type type, string name, string memberName, bool isWritable, bool isReadable) + { + this.Name = name; + this.MemberName = memberName; + this.Type = type; + this.IsWritable = isWritable; + this.IsReadable = isReadable; + } + public MetaMember(FieldInfo info, string name, bool allowPrivate) { this.Name = name; this.MemberName = info.Name; this.FieldInfo = info; + this.Type = info.FieldType; this.IsReadable = allowPrivate || info.IsPublic; this.IsWritable = allowPrivate || (info.IsPublic && !info.IsInitOnly); this.ShouldSerializeMethodInfo = GetShouldSerialize(info); @@ -43,6 +53,7 @@ public MetaMember(PropertyInfo info, string name, bool allowPrivate) this.Name = name; this.MemberName = info.Name; this.PropertyInfo = info; + this.Type = info.PropertyType; this.IsReadable = (getMethod != null) && (allowPrivate || getMethod.IsPublic) && !getMethod.IsStatic; this.IsWritable = (setMethod != null) && (allowPrivate || setMethod.IsPublic) && !setMethod.IsStatic; this.ShouldSerializeMethodInfo = GetShouldSerialize(info); @@ -58,28 +69,23 @@ static MethodInfo GetShouldSerialize(MemberInfo info) .FirstOrDefault(); } - public bool IsDeclaredIsValueType - { - get - { - var mi = IsProperty ? (MemberInfo)PropertyInfo : FieldInfo; - return mi.DeclaringType.GetTypeInfo().IsValueType; - } - } - public T GetCustomAttribute(bool inherit) where T : Attribute { if (IsProperty) { return PropertyInfo.GetCustomAttribute(inherit); } - else + else if (FieldInfo != null) { return FieldInfo.GetCustomAttribute(inherit); } + else + { + return null; + } } - public void EmitLoadValue(ILGenerator il) + public virtual void EmitLoadValue(ILGenerator il) { if (IsProperty) { @@ -91,7 +97,7 @@ public void EmitLoadValue(ILGenerator il) } } - public void EmitStoreValue(ILGenerator il) + public virtual void EmitStoreValue(ILGenerator il) { if (IsProperty) { @@ -103,4 +109,64 @@ public void EmitStoreValue(ILGenerator il) } } } -} + + // used for serialize exception... + internal class StringConstantValueMetaMember : MetaMember + { + readonly string constant; + + public StringConstantValueMetaMember(string name, string constant) + : base(typeof(String), name, name, false, true) + { + this.constant = constant; + } + + public override void EmitLoadValue(ILGenerator il) + { + il.Emit(OpCodes.Pop); // pop load instance + il.Emit(OpCodes.Ldstr, constant); + } + + public override void EmitStoreValue(ILGenerator il) + { + throw new NotSupportedException(); + } + } + + // used for serialize exception... + internal class InnerExceptionMetaMember : MetaMember + { + static readonly MethodInfo getInnerException = ExpressionUtility.GetPropertyInfo((Exception ex) => ex.InnerException).GetGetMethod(); + static readonly MethodInfo nongenericSerialize = ExpressionUtility.GetMethodInfo(writer => JsonSerializer.NonGeneric.Serialize(ref writer, default(object), default(IJsonFormatterResolver))); + + // set after... + internal ArgumentField argWriter; + internal ArgumentField argValue; + internal ArgumentField argResolver; + + public InnerExceptionMetaMember(string name) + : base(typeof(Exception), name, name, false, true) + { + } + + public override void EmitLoadValue(ILGenerator il) + { + il.Emit(OpCodes.Callvirt, getInnerException); + } + + public override void EmitStoreValue(ILGenerator il) + { + throw new NotSupportedException(); + } + + public void EmitSerializeDirectly(ILGenerator il) + { + // JsonSerializer.NonGeneric.Serialize(ref writer, value.InnerException, formatterResolver); + argWriter.EmitLoad(); + argValue.EmitLoad(); + il.Emit(OpCodes.Callvirt, getInnerException); + argResolver.EmitLoad(); + il.EmitCall(nongenericSerialize); + } + } +} \ No newline at end of file diff --git a/src/Utf8Json/Internal/Emit/MetaType.cs b/src/Utf8Json/Internal/Emit/MetaType.cs index 395516a..bdeed84 100644 --- a/src/Utf8Json/Internal/Emit/MetaType.cs +++ b/src/Utf8Json/Internal/Emit/MetaType.cs @@ -13,9 +13,9 @@ internal class MetaType public bool IsStruct { get { return !IsClass; } } public bool IsConcreteClass { get; private set; } - public ConstructorInfo BestmatchConstructor { get; private set; } - public MetaMember[] ConstructorParameters { get; private set; } - public MetaMember[] Members { get; private set; } + public ConstructorInfo BestmatchConstructor { get; internal set; } + public MetaMember[] ConstructorParameters { get; internal set; } + public MetaMember[] Members { get; internal set; } public MetaType(Type type, Func nameMutetor, bool allowPrivate) { diff --git a/src/Utf8Json/JsonSerializer.NonGeneric.cs b/src/Utf8Json/JsonSerializer.NonGeneric.cs index 927c7ad..b51dc32 100644 --- a/src/Utf8Json/JsonSerializer.NonGeneric.cs +++ b/src/Utf8Json/JsonSerializer.NonGeneric.cs @@ -135,6 +135,19 @@ public static System.Threading.Tasks.Task SerializeAsync(Type type, Stream strea #endif + public static void Serialize(ref JsonWriter writer, object value, IJsonFormatterResolver resolver) + { + if (value == null) + { + writer.WriteNull(); + return; + } + else + { + Serialize(value.GetType(), ref writer, value, resolver); + } + } + public static void Serialize(Type type, ref JsonWriter writer, object value) { Serialize(type, ref writer, value, defaultResolver); diff --git a/src/Utf8Json/Resolvers/DynamicGenericResolver.cs b/src/Utf8Json/Resolvers/DynamicGenericResolver.cs index 0557e81..643cdc3 100644 --- a/src/Utf8Json/Resolvers/DynamicGenericResolver.cs +++ b/src/Utf8Json/Resolvers/DynamicGenericResolver.cs @@ -295,11 +295,6 @@ internal static object GetFormatter(Type t) { return Activator.CreateInstance(typeof(NonGenericDictionaryFormatter<>).MakeGenericType(t)); } - // Exception - if (typeof(Exception).GetTypeInfo().IsAssignableFrom(ti)) - { - return Activator.CreateInstance(typeof(ExceptionFormatter<>).MakeGenericType(t)); - } } return null; diff --git a/src/Utf8Json/Resolvers/DynamicObjectResolver.cs b/src/Utf8Json/Resolvers/DynamicObjectResolver.cs index c26bc6f..a6f8e06 100644 --- a/src/Utf8Json/Resolvers/DynamicObjectResolver.cs +++ b/src/Utf8Json/Resolvers/DynamicObjectResolver.cs @@ -537,9 +537,13 @@ public static object BuildFormatterToAssembly(DynamicAssembly assembly, IJson } Type elementType; - if (ti.IsAnonymous() || TryGetInterfaceEnumerableElementType(typeof(T), out elementType)) + if (typeof(Exception).GetTypeInfo().IsAssignableFrom(ti)) { - return DynamicObjectTypeBuilder.BuildAnonymousFormatter(typeof(T), nameMutator, excludeNull, false); + return DynamicObjectTypeBuilder.BuildAnonymousFormatter(typeof(T), nameMutator, excludeNull, false, true); + } + else if (ti.IsAnonymous() || TryGetInterfaceEnumerableElementType(typeof(T), out elementType)) + { + return DynamicObjectTypeBuilder.BuildAnonymousFormatter(typeof(T), nameMutator, excludeNull, false, false); } var formatterTypeInfo = DynamicObjectTypeBuilder.BuildType(assembly, typeof(T), nameMutator, excludeNull); @@ -563,8 +567,14 @@ public static object BuildFormatterToDynamicMethod(IJsonFormatterResolver sel } return (IJsonFormatter)Activator.CreateInstance(typeof(StaticNullableFormatter<>).MakeGenericType(ti.AsType()), new object[] { innerFormatter }); } - - return DynamicObjectTypeBuilder.BuildAnonymousFormatter(typeof(T), nameMutator, excludeNull, allowPrivate); + if (typeof(Exception).GetTypeInfo().IsAssignableFrom(ti)) + { + return DynamicObjectTypeBuilder.BuildAnonymousFormatter(typeof(T), nameMutator, excludeNull, false, true); + } + else + { + return DynamicObjectTypeBuilder.BuildAnonymousFormatter(typeof(T), nameMutator, excludeNull, allowPrivate, false); + } } static TypeInfo BuildType(DynamicAssembly assembly, Type type, Func nameMutator, bool excludeNull) @@ -630,11 +640,32 @@ static TypeInfo BuildType(DynamicAssembly assembly, Type type, Func nameMutator, bool excludeNull, bool allowPrivate) + public static object BuildAnonymousFormatter(Type type, Func nameMutator, bool excludeNull, bool allowPrivate, bool isException) { if (ignoreTypes.Contains(type)) return false; - var serializationInfo = new MetaType(type, nameMutator, allowPrivate); // can be allowPrivate:true + MetaType serializationInfo; + if (isException) + { + var ignoreSet = new HashSet(new[] + { + "HelpLink", "TargetSite", "HResult", "Data", "ClassName", "InnerException" + }.Select(x => nameMutator(x))); + + // special case for exception, modify + serializationInfo = new MetaType(type, nameMutator, false); + + serializationInfo.BestmatchConstructor = null; + serializationInfo.ConstructorParameters = new MetaMember[0]; + serializationInfo.Members = new[] { new StringConstantValueMetaMember(nameMutator("ClassName"), type.FullName) } + .Concat(serializationInfo.Members.Where(x => !ignoreSet.Contains(x.Name))) + .Concat(new[] { new InnerExceptionMetaMember(nameMutator("InnerException")) }) + .ToArray(); + } + else + { + serializationInfo = new MetaType(type, nameMutator, allowPrivate); // can be allowPrivate:true + } var hasShouldSerialize = serializationInfo.Members.Any(x => x.ShouldSerializeMethodInfo != null); // build instance instead of emit constructor. @@ -832,6 +863,15 @@ static void BuildSerialize(Type type, MetaType info, ILGenerator il, Action emit var argValue = new ArgumentField(il, firstArgIndex + 1, type); var argResolver = new ArgumentField(il, firstArgIndex + 2); + // special case for serialize exception... + var innerExceptionMetaMember = info.Members.OfType().FirstOrDefault(); + if (innerExceptionMetaMember != null) + { + innerExceptionMetaMember.argWriter = argWriter; + innerExceptionMetaMember.argValue = argValue; + innerExceptionMetaMember.argResolver = argResolver; + } + var typeInfo = type.GetTypeInfo(); // Special case for serialize IEnumerable<>. @@ -903,7 +943,7 @@ static void BuildSerialize(Type type, MetaType info, ILGenerator il, Action emit il.EmitCall(EmitInfo.GetNullableHasValue(item.Type.GetGenericArguments()[0])); il.Emit(OpCodes.Brfalse_S, (index < labels.Length - 1) ? labels[index + 1] : endObjectLabel); // null, next label } - else if (!item.Type.IsValueType) + else if (!item.Type.IsValueType && !(item is StringConstantValueMetaMember)) { argValue.EmitLoad(); item.EmitLoadValue(il); @@ -983,7 +1023,11 @@ static void BuildSerialize(Type type, MetaType info, ILGenerator il, Action emit static void EmitSerializeValue(TypeInfo type, MetaMember member, ILGenerator il, int index, Func tryEmitLoadCustomFormatter, ArgumentField writer, ArgumentField argValue, ArgumentField argResolver) { var t = member.Type; - if (tryEmitLoadCustomFormatter(index, member)) + if (member is InnerExceptionMetaMember) + { + (member as InnerExceptionMetaMember).EmitSerializeDirectly(il); + } + else if (tryEmitLoadCustomFormatter(index, member)) { writer.EmitLoad(); argValue.EmitLoad(); diff --git a/tests/Utf8Json.Tests/ExceptionTest.cs b/tests/Utf8Json.Tests/ExceptionTest.cs index 368165d..0b7cbbe 100644 --- a/tests/Utf8Json.Tests/ExceptionTest.cs +++ b/tests/Utf8Json.Tests/ExceptionTest.cs @@ -18,27 +18,50 @@ public class ExceptionTest [Fact] public void Root1() { - var ex = new Exception("ABC"); - var json = JsonSerializer.ToJsonString(ex); - json.Is("{\"ClassName\":\"System.Exception\",\"Message\":\"ABC\",\"Source\":null,\"StackTrace\":null}"); + { + var ex = new Exception("ABC"); + var json = JsonSerializer.ToJsonString(ex); + json.Is("{\"ClassName\":\"System.Exception\",\"Message\":\"ABC\",\"StackTrace\":null,\"Source\":null,\"InnerException\":null}"); + } + { + var ex = new Exception("ABC"); + var json = JsonSerializer.ToJsonString(ex, Utf8Json.Resolvers.StandardResolver.ExcludeNullSnakeCase); + json.Is("{\"class_name\":\"System.Exception\",\"message\":\"ABC\"}"); + } } [Fact] public void Root2() { - var ex = new FooException { Bar = 100 }; + { + var ex = new FooException { Bar = 100 }; - var json = JsonSerializer.ToJsonString(ex); - json.Is("{\"ClassName\":\"Utf8Json.Tests.FooException\",\"Message\":\"BCD\",\"Source\":null,\"StackTrace\":null}"); + var json = JsonSerializer.ToJsonString(ex); + json.Is("{\"ClassName\":\"Utf8Json.Tests.FooException\",\"Bar\":100,\"Message\":\"BCD\",\"StackTrace\":null,\"Source\":null,\"InnerException\":null}"); + } + { + var ex = new FooException { Bar = 100 }; + + var json = JsonSerializer.ToJsonString(ex, Utf8Json.Resolvers.StandardResolver.ExcludeNullSnakeCase); + json.Is("{\"class_name\":\"Utf8Json.Tests.FooException\",\"bar\":100,\"message\":\"BCD\"}"); + } } [Fact] public void Inner() { - var ex = new Exception("ABC", new FooException { Bar = 100 }); + { + var ex = new Exception("ABC", new FooException { Bar = 100 }); + + var json = JsonSerializer.ToJsonString(ex); + json.Is("{\"ClassName\":\"System.Exception\",\"Message\":\"ABC\",\"StackTrace\":null,\"Source\":null,\"InnerException\":{\"ClassName\":\"Utf8Json.Tests.FooException\",\"Bar\":100,\"Message\":\"BCD\",\"StackTrace\":null,\"Source\":null,\"InnerException\":null}}"); + } + { + var ex = new Exception("ABC", new FooException { Bar = 100 }); - var json = JsonSerializer.ToJsonString(ex); - json.Is("{\"ClassName\":\"System.Exception\",\"Message\":\"ABC\",\"Source\":null,\"StackTrace\":null,\"InnerException\":{\"ClassName\":\"Utf8Json.Tests.FooException\",\"Message\":\"BCD\",\"Source\":null,\"StackTrace\":null}}"); + var json = JsonSerializer.ToJsonString(ex, Utf8Json.Resolvers.StandardResolver.ExcludeNullSnakeCase); + json.Is("{\"class_name\":\"System.Exception\",\"message\":\"ABC\",\"inner_exception\":{\"class_name\":\"Utf8Json.Tests.FooException\",\"bar\":100,\"message\":\"BCD\"}}"); + } } } } From 22ddf77457489035d51606f4dad254e25ebed3a1 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Mon, 22 Jan 2018 20:50:22 +0900 Subject: [PATCH 04/12] fix generate invalid length copy when ExcludeNull #37 --- src/Utf8Json/Resolvers/DynamicObjectResolver.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Utf8Json/Resolvers/DynamicObjectResolver.cs b/src/Utf8Json/Resolvers/DynamicObjectResolver.cs index a6f8e06..b19cba0 100644 --- a/src/Utf8Json/Resolvers/DynamicObjectResolver.cs +++ b/src/Utf8Json/Resolvers/DynamicObjectResolver.cs @@ -980,7 +980,16 @@ static void BuildSerialize(Type type, MetaType info, ILGenerator il, Action emit il.EmitLdc_I4(index); il.Emit(OpCodes.Ldelem_Ref); #if NETSTANDARD - byte[] rawField = (index == 0) ? JsonWriter.GetEncodedPropertyNameWithBeginObject(item.Name) : JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator(item.Name); + // same as in constructor + byte[] rawField; + if (excludeNull || hasShouldSerialize) + { + rawField = JsonWriter.GetEncodedPropertyName(item.Name); + } + else + { + rawField = (index == 0) ? JsonWriter.GetEncodedPropertyNameWithBeginObject(item.Name) : JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator(item.Name); + } if (rawField.Length < 32) { if (UnsafeMemory.Is32Bit) From b9a4630633f22a05c667b32f3fa8d79d8c93d558 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Mon, 22 Jan 2018 20:52:31 +0900 Subject: [PATCH 05/12] ready for 1.3.6 --- docs/Utf8Json.AspNetCoreMvcFormatter.nuspec | 6 +++--- docs/Utf8Json.ImmutableCollection.nuspec | 8 ++++---- docs/Utf8Json.UnityShims.nuspec | 8 ++++---- docs/Utf8Json.nuspec | 2 +- docs/push.bat | 8 ++++---- src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs | 4 ++-- src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs | 4 ++-- src/Utf8Json.UnityClient/Assembly-CSharp.csproj | 1 - src/Utf8Json.UnityShims/_AssemblyInfo.cs | 4 ++-- src/Utf8Json/_AssemblyInfo.cs | 4 ++-- 10 files changed, 24 insertions(+), 25 deletions(-) diff --git a/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec b/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec index d5c16e2..2a80416 100644 --- a/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec +++ b/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec @@ -2,7 +2,7 @@ Utf8Json.AspNetCoreMvcFormatter - 1.3.5 + 1.3.6 Utf8Json AspNetCoreMvcFormatter neuecc neuecc @@ -13,11 +13,11 @@ Json, Serialization, Formatter, Serializer, Unity, Xamarin, ASPNET - + - + diff --git a/docs/Utf8Json.ImmutableCollection.nuspec b/docs/Utf8Json.ImmutableCollection.nuspec index 172bf9e..adfdbc1 100644 --- a/docs/Utf8Json.ImmutableCollection.nuspec +++ b/docs/Utf8Json.ImmutableCollection.nuspec @@ -2,7 +2,7 @@ Utf8Json.ImmutableCollection - 1.3.5 + 1.3.6 Utf8Json Extension Resolver for ImmutableCollection neuecc neuecc @@ -12,15 +12,15 @@ Json, Serialization, Formatter, Serializer, Unity, Xamarin - + - + - + diff --git a/docs/Utf8Json.UnityShims.nuspec b/docs/Utf8Json.UnityShims.nuspec index 5dfb0ad..5ab0410 100644 --- a/docs/Utf8Json.UnityShims.nuspec +++ b/docs/Utf8Json.UnityShims.nuspec @@ -2,7 +2,7 @@ Utf8Json.UnityShims - 1.3.5 + 1.3.6 Utf8Json UnityShims neuecc neuecc @@ -12,15 +12,15 @@ Json, Serialization, Formatter, Serializer, Unity, Xamarin - + - + - + diff --git a/docs/Utf8Json.nuspec b/docs/Utf8Json.nuspec index d2bd9e7..d304b85 100644 --- a/docs/Utf8Json.nuspec +++ b/docs/Utf8Json.nuspec @@ -2,7 +2,7 @@ Utf8Json - 1.3.5 + 1.3.6 Utf8Json neuecc neuecc diff --git a/docs/push.bat b/docs/push.bat index c4b0ec7..1f2c778 100644 --- a/docs/push.bat +++ b/docs/push.bat @@ -1,4 +1,4 @@ -nuget push Utf8Json.1.3.5.nupkg -Source https://www.nuget.org/api/v2/package -nuget push Utf8Json.ImmutableCollection.1.3.5.nupkg -Source https://www.nuget.org/api/v2/package -nuget push Utf8Json.UnityShims.1.3.5.nupkg -Source https://www.nuget.org/api/v2/package -nuget push Utf8Json.AspNetCoreMvcFormatter.1.3.5.nupkg -Source https://www.nuget.org/api/v2/package \ No newline at end of file +nuget push Utf8Json.1.3.6.nupkg -Source https://www.nuget.org/api/v2/package +nuget push Utf8Json.ImmutableCollection.1.3.6.nupkg -Source https://www.nuget.org/api/v2/package +nuget push Utf8Json.UnityShims.1.3.6.nupkg -Source https://www.nuget.org/api/v2/package +nuget push Utf8Json.AspNetCoreMvcFormatter.1.3.6.nupkg -Source https://www.nuget.org/api/v2/package \ No newline at end of file diff --git a/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs b/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs index 7508bd4..e64b42f 100644 --- a/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs +++ b/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("899f8b6c-c4c7-4e8b-9875-f61fdfb630bd")] -[assembly: AssemblyVersion("1.3.5")] -[assembly: AssemblyFileVersion("1.3.5")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.6")] +[assembly: AssemblyFileVersion("1.3.6")] \ No newline at end of file diff --git a/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs b/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs index 5e76789..5cca208 100644 --- a/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs +++ b/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("2e7ac239-3db1-4772-9f47-5f62abb56ed0")] -[assembly: AssemblyVersion("1.3.5")] -[assembly: AssemblyFileVersion("1.3.5")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.6")] +[assembly: AssemblyFileVersion("1.3.6")] \ No newline at end of file diff --git a/src/Utf8Json.UnityClient/Assembly-CSharp.csproj b/src/Utf8Json.UnityClient/Assembly-CSharp.csproj index 10e2ce0..8d369e0 100644 --- a/src/Utf8Json.UnityClient/Assembly-CSharp.csproj +++ b/src/Utf8Json.UnityClient/Assembly-CSharp.csproj @@ -63,7 +63,6 @@ - diff --git a/src/Utf8Json.UnityShims/_AssemblyInfo.cs b/src/Utf8Json.UnityShims/_AssemblyInfo.cs index 2185438..b126a11 100644 --- a/src/Utf8Json.UnityShims/_AssemblyInfo.cs +++ b/src/Utf8Json.UnityShims/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("bf5d0a42-70b7-417d-af8c-2f7e073057e2")] -[assembly: AssemblyVersion("1.3.5")] -[assembly: AssemblyFileVersion("1.3.5")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.6")] +[assembly: AssemblyFileVersion("1.3.6")] \ No newline at end of file diff --git a/src/Utf8Json/_AssemblyInfo.cs b/src/Utf8Json/_AssemblyInfo.cs index 5d5759f..51c48e9 100644 --- a/src/Utf8Json/_AssemblyInfo.cs +++ b/src/Utf8Json/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("929e3779-4c3a-42a3-bc72-3d77511e988f")] -[assembly: AssemblyVersion("1.3.5")] -[assembly: AssemblyFileVersion("1.3.5")] +[assembly: AssemblyVersion("1.3.6")] +[assembly: AssemblyFileVersion("1.3.6")] From 3ecadc73e0d68e051f4e25ceb795ddfa2b045a8f Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Tue, 23 Jan 2018 18:34:30 +0900 Subject: [PATCH 06/12] serialize Exception route to concrete type #41 --- sandbox/ConsoleAppNetCore/Program.cs | 22 ++++++----- .../Resolvers/DynamicObjectResolver.cs | 39 ++++++++++++++++++- tests/Utf8Json.Tests/ExceptionTest.cs | 4 +- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/sandbox/ConsoleAppNetCore/Program.cs b/sandbox/ConsoleAppNetCore/Program.cs index 5f8761a..9aa2b81 100644 --- a/sandbox/ConsoleAppNetCore/Program.cs +++ b/sandbox/ConsoleAppNetCore/Program.cs @@ -331,20 +331,24 @@ public void SetId(Guid id) } } + public sealed class Entry + { + public int Number { get; set; } + public Exception Exception { get; set; } + } + static unsafe void Main(string[] args) { - try + var argNullEx = new ArgumentNullException("cooCoo", "parameter cannot be null"); + var payload = new Entry { - throw new Exception("ABC", new FooException { Bar = 100 }); - } - catch (Exception ex) - { - var json = JsonSerializer.ToJsonString(ex, Utf8Json.Resolvers.StandardResolver.Default); - Console.WriteLine(JsonSerializer.PrettyPrint(json)); + Number = 1, + Exception = argNullEx + }; - //Console.WriteLine(json); - } + var json1 = Utf8Json.JsonSerializer.ToJsonString(payload, StandardResolver.AllowPrivateCamelCase); + Console.WriteLine(JsonSerializer.PrettyPrint(json1)); } static (int, int[]) Array(int[] xs) diff --git a/src/Utf8Json/Resolvers/DynamicObjectResolver.cs b/src/Utf8Json/Resolvers/DynamicObjectResolver.cs index b19cba0..47acd8b 100644 --- a/src/Utf8Json/Resolvers/DynamicObjectResolver.cs +++ b/src/Utf8Json/Resolvers/DynamicObjectResolver.cs @@ -863,6 +863,8 @@ static void BuildSerialize(Type type, MetaType info, ILGenerator il, Action emit var argValue = new ArgumentField(il, firstArgIndex + 1, type); var argResolver = new ArgumentField(il, firstArgIndex + 2); + var typeInfo = type.GetTypeInfo(); + // special case for serialize exception... var innerExceptionMetaMember = info.Members.OfType().FirstOrDefault(); if (innerExceptionMetaMember != null) @@ -872,8 +874,6 @@ static void BuildSerialize(Type type, MetaType info, ILGenerator il, Action emit innerExceptionMetaMember.argResolver = argResolver; } - var typeInfo = type.GetTypeInfo(); - // Special case for serialize IEnumerable<>. if (info.IsClass && info.BestmatchConstructor == null) { @@ -909,6 +909,37 @@ static void BuildSerialize(Type type, MetaType info, ILGenerator il, Action emit il.MarkLabel(elseBody); } + // special case for exception + if (type == typeof(Exception)) + { + //var exceptionType = value.GetType(); + //if (exceptionType != typeof(Exception)) + //{ + // JsonSerializer.NonGeneric.Serialize(exceptionType, ref writer, value, formatterResolver); + // return; + //} + + var elseBody = il.DefineLabel(); + var exceptionType = il.DeclareLocal(typeof(Type)); + argValue.EmitLoad(); + il.EmitCall(EmitInfo.GetTypeMethod); + il.EmitStloc(exceptionType); + il.EmitLdloc(exceptionType); + il.Emit(OpCodes.Ldtoken, typeof(Exception)); + il.EmitCall(EmitInfo.GetTypeFromHandle); + il.EmitCall(EmitInfo.TypeOpInequality); + il.Emit(OpCodes.Brfalse, elseBody); + + il.EmitLdloc(exceptionType); + argWriter.EmitLoad(); + argValue.EmitLoad(); + argResolver.EmitLoad(); + il.EmitCall(EmitInfo.NongenericSerialize); + il.Emit(OpCodes.Ret); // return; + + il.MarkLabel(elseBody); + } + // for-loop WriteRaw -> WriteValue, EndObject LocalBuilder wrote = null; Label endObjectLabel = il.DefineLabel(); @@ -1467,6 +1498,10 @@ internal static class EmitInfo public static readonly MethodInfo ActivatorCreateInstance = ExpressionUtility.GetMethodInfo(() => Activator.CreateInstance(default(Type), default(object[]))); public static readonly MethodInfo GetUninitializedObject = ExpressionUtility.GetMethodInfo(() => System.Runtime.Serialization.FormatterServices.GetUninitializedObject(default(Type))); + public static readonly MethodInfo GetTypeMethod = ExpressionUtility.GetMethodInfo((object o) => o.GetType()); + public static readonly MethodInfo TypeOpInequality = typeof(Type).GetTypeInfo().GetRuntimeMethods().First(x => x.Name == "op_Inequality"); + public static readonly MethodInfo NongenericSerialize = ExpressionUtility.GetMethodInfo(writer => JsonSerializer.NonGeneric.Serialize(default(Type), ref writer, default(object), default(IJsonFormatterResolver))); + public static MethodInfo Serialize(Type type) { return typeof(IJsonFormatter<>).MakeGenericType(type).GetRuntimeMethod("Serialize", new[] { typeof(Utf8Json.JsonWriter).MakeByRefType(), type, typeof(IJsonFormatterResolver) }); diff --git a/tests/Utf8Json.Tests/ExceptionTest.cs b/tests/Utf8Json.Tests/ExceptionTest.cs index 0b7cbbe..e91909c 100644 --- a/tests/Utf8Json.Tests/ExceptionTest.cs +++ b/tests/Utf8Json.Tests/ExceptionTest.cs @@ -34,13 +34,13 @@ public void Root1() public void Root2() { { - var ex = new FooException { Bar = 100 }; + FooException ex = new FooException { Bar = 100 }; var json = JsonSerializer.ToJsonString(ex); json.Is("{\"ClassName\":\"Utf8Json.Tests.FooException\",\"Bar\":100,\"Message\":\"BCD\",\"StackTrace\":null,\"Source\":null,\"InnerException\":null}"); } { - var ex = new FooException { Bar = 100 }; + Exception ex = new FooException { Bar = 100 }; var json = JsonSerializer.ToJsonString(ex, Utf8Json.Resolvers.StandardResolver.ExcludeNullSnakeCase); json.Is("{\"class_name\":\"Utf8Json.Tests.FooException\",\"bar\":100,\"message\":\"BCD\"}"); From 9c6240987b3b7f1642c63c1889c0648b7177ad0a Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Tue, 23 Jan 2018 18:37:39 +0900 Subject: [PATCH 07/12] ready for 1.3.6.1 --- docs/Utf8Json.AspNetCoreMvcFormatter.nuspec | 6 +++--- docs/Utf8Json.ImmutableCollection.nuspec | 8 ++++---- docs/Utf8Json.UnityShims.nuspec | 8 ++++---- docs/Utf8Json.nuspec | 2 +- docs/push.bat | 8 ++++---- src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs | 4 ++-- src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs | 4 ++-- src/Utf8Json.UnityShims/_AssemblyInfo.cs | 4 ++-- src/Utf8Json/_AssemblyInfo.cs | 4 ++-- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec b/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec index 2a80416..2d9000b 100644 --- a/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec +++ b/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec @@ -2,7 +2,7 @@ Utf8Json.AspNetCoreMvcFormatter - 1.3.6 + 1.3.6.1 Utf8Json AspNetCoreMvcFormatter neuecc neuecc @@ -13,11 +13,11 @@ Json, Serialization, Formatter, Serializer, Unity, Xamarin, ASPNET - + - + diff --git a/docs/Utf8Json.ImmutableCollection.nuspec b/docs/Utf8Json.ImmutableCollection.nuspec index adfdbc1..3d52de8 100644 --- a/docs/Utf8Json.ImmutableCollection.nuspec +++ b/docs/Utf8Json.ImmutableCollection.nuspec @@ -2,7 +2,7 @@ Utf8Json.ImmutableCollection - 1.3.6 + 1.3.6.1 Utf8Json Extension Resolver for ImmutableCollection neuecc neuecc @@ -12,15 +12,15 @@ Json, Serialization, Formatter, Serializer, Unity, Xamarin - + - + - + diff --git a/docs/Utf8Json.UnityShims.nuspec b/docs/Utf8Json.UnityShims.nuspec index 5ab0410..032b7e4 100644 --- a/docs/Utf8Json.UnityShims.nuspec +++ b/docs/Utf8Json.UnityShims.nuspec @@ -2,7 +2,7 @@ Utf8Json.UnityShims - 1.3.6 + 1.3.6.1 Utf8Json UnityShims neuecc neuecc @@ -12,15 +12,15 @@ Json, Serialization, Formatter, Serializer, Unity, Xamarin - + - + - + diff --git a/docs/Utf8Json.nuspec b/docs/Utf8Json.nuspec index d304b85..1531c9f 100644 --- a/docs/Utf8Json.nuspec +++ b/docs/Utf8Json.nuspec @@ -2,7 +2,7 @@ Utf8Json - 1.3.6 + 1.3.6.1 Utf8Json neuecc neuecc diff --git a/docs/push.bat b/docs/push.bat index 1f2c778..25fdb0e 100644 --- a/docs/push.bat +++ b/docs/push.bat @@ -1,4 +1,4 @@ -nuget push Utf8Json.1.3.6.nupkg -Source https://www.nuget.org/api/v2/package -nuget push Utf8Json.ImmutableCollection.1.3.6.nupkg -Source https://www.nuget.org/api/v2/package -nuget push Utf8Json.UnityShims.1.3.6.nupkg -Source https://www.nuget.org/api/v2/package -nuget push Utf8Json.AspNetCoreMvcFormatter.1.3.6.nupkg -Source https://www.nuget.org/api/v2/package \ No newline at end of file +nuget push Utf8Json.1.3.6.1.nupkg -Source https://www.nuget.org/api/v2/package +nuget push Utf8Json.ImmutableCollection.1.3.6.1.nupkg -Source https://www.nuget.org/api/v2/package +nuget push Utf8Json.UnityShims.1.3.6.1.nupkg -Source https://www.nuget.org/api/v2/package +nuget push Utf8Json.AspNetCoreMvcFormatter.1.3.6.1.nupkg -Source https://www.nuget.org/api/v2/package \ No newline at end of file diff --git a/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs b/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs index e64b42f..eccd998 100644 --- a/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs +++ b/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("899f8b6c-c4c7-4e8b-9875-f61fdfb630bd")] -[assembly: AssemblyVersion("1.3.6")] -[assembly: AssemblyFileVersion("1.3.6")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.6.1")] +[assembly: AssemblyFileVersion("1.3.6.1")] \ No newline at end of file diff --git a/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs b/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs index 5cca208..40ff535 100644 --- a/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs +++ b/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("2e7ac239-3db1-4772-9f47-5f62abb56ed0")] -[assembly: AssemblyVersion("1.3.6")] -[assembly: AssemblyFileVersion("1.3.6")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.6.1")] +[assembly: AssemblyFileVersion("1.3.6.1")] \ No newline at end of file diff --git a/src/Utf8Json.UnityShims/_AssemblyInfo.cs b/src/Utf8Json.UnityShims/_AssemblyInfo.cs index b126a11..aecb018 100644 --- a/src/Utf8Json.UnityShims/_AssemblyInfo.cs +++ b/src/Utf8Json.UnityShims/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("bf5d0a42-70b7-417d-af8c-2f7e073057e2")] -[assembly: AssemblyVersion("1.3.6")] -[assembly: AssemblyFileVersion("1.3.6")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.6.1")] +[assembly: AssemblyFileVersion("1.3.6.1")] \ No newline at end of file diff --git a/src/Utf8Json/_AssemblyInfo.cs b/src/Utf8Json/_AssemblyInfo.cs index 51c48e9..1f96370 100644 --- a/src/Utf8Json/_AssemblyInfo.cs +++ b/src/Utf8Json/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("929e3779-4c3a-42a3-bc72-3d77511e988f")] -[assembly: AssemblyVersion("1.3.6")] -[assembly: AssemblyFileVersion("1.3.6")] +[assembly: AssemblyVersion("1.3.6.1")] +[assembly: AssemblyFileVersion("1.3.6.1")] From a9b7dc7792c329285d7d5a4b8300b949ca3a3aff Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Tue, 30 Jan 2018 11:28:46 +0900 Subject: [PATCH 08/12] support base class private member deserialize #43 --- sandbox/ConsoleAppNetCore/Program.cs | 24 ++++++---- src/Utf8Json/Internal/Emit/MetaType.cs | 5 +- src/Utf8Json/Internal/ReflectionExtensions.cs | 46 +++++++++++++++++++ .../BassClassDeserializeTest.cs | 40 ++++++++++++++++ 4 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 tests/Utf8Json.Tests/BassClassDeserializeTest.cs diff --git a/sandbox/ConsoleAppNetCore/Program.cs b/sandbox/ConsoleAppNetCore/Program.cs index 9aa2b81..0200c44 100644 --- a/sandbox/ConsoleAppNetCore/Program.cs +++ b/sandbox/ConsoleAppNetCore/Program.cs @@ -17,6 +17,19 @@ public class FooException : Exception namespace ConsoleAppNetCore { + public abstract class JsonDBItem + { + public int ID { get { return _id; } } + private int _id = -1; + } + + public class Card : JsonDBItem + { + public string Name { get { return name; } } + private string name = "0"; + } + + public class CustomPoint { public readonly int X; @@ -340,15 +353,10 @@ public sealed class Entry static unsafe void Main(string[] args) { - var argNullEx = new ArgumentNullException("cooCoo", "parameter cannot be null"); - var payload = new Entry - { - Number = 1, - Exception = argNullEx - }; - var json1 = Utf8Json.JsonSerializer.ToJsonString(payload, StandardResolver.AllowPrivateCamelCase); - Console.WriteLine(JsonSerializer.PrettyPrint(json1)); + var huga = JsonSerializer.Serialize(new Card()); + + } static (int, int[]) Array(int[] xs) diff --git a/src/Utf8Json/Internal/Emit/MetaType.cs b/src/Utf8Json/Internal/Emit/MetaType.cs index bdeed84..c7d4e40 100644 --- a/src/Utf8Json/Internal/Emit/MetaType.cs +++ b/src/Utf8Json/Internal/Emit/MetaType.cs @@ -26,8 +26,7 @@ public MetaType(Type type, Func nameMutetor, bool allowPrivate) var stringMembers = new Dictionary(); { - // All public members are serialize target except [Ignore] member. - foreach (var item in type.GetRuntimeProperties()) + foreach (var item in type.GetAllProperties()) { if (item.GetIndexParameters().Length > 0) continue; // skip indexer if (item.GetCustomAttribute(true) != null) continue; @@ -44,7 +43,7 @@ public MetaType(Type type, Func nameMutetor, bool allowPrivate) } stringMembers.Add(member.Name, member); } - foreach (var item in type.GetRuntimeFields()) + foreach (var item in type.GetAllFields()) { if (item.GetCustomAttribute(true) != null) continue; if (item.GetCustomAttribute(true) != null) continue; diff --git a/src/Utf8Json/Internal/ReflectionExtensions.cs b/src/Utf8Json/Internal/ReflectionExtensions.cs index 29abdde..93e1692 100644 --- a/src/Utf8Json/Internal/ReflectionExtensions.cs +++ b/src/Utf8Json/Internal/ReflectionExtensions.cs @@ -26,6 +26,52 @@ public static bool IsAnonymous(this System.Reflection.TypeInfo type) && (type.Attributes & TypeAttributes.NotPublic) == TypeAttributes.NotPublic; } + public static IEnumerable GetAllProperties(this Type type) + { + return GetAllPropertiesCore(type, new HashSet()); + } + + static IEnumerable GetAllPropertiesCore(Type type, HashSet nameCheck) + { + foreach (var item in type.GetRuntimeProperties()) + { + if (nameCheck.Add(item.Name)) + { + yield return item; + } + } + if (type.BaseType != null) + { + foreach (var item in GetAllPropertiesCore(type.BaseType, nameCheck)) + { + yield return item; + } + } + } + + public static IEnumerable GetAllFields(this Type type) + { + return GetAllFieldsCore(type, new HashSet()); + } + + static IEnumerable GetAllFieldsCore(Type type, HashSet nameCheck) + { + foreach (var item in type.GetRuntimeFields()) + { + if (nameCheck.Add(item.Name)) + { + yield return item; + } + } + if (type.BaseType != null) + { + foreach (var item in GetAllFieldsCore(type.BaseType, nameCheck)) + { + yield return item; + } + } + } + #if NETSTANDARD public static bool IsConstructedGenericType(this System.Reflection.TypeInfo type) diff --git a/tests/Utf8Json.Tests/BassClassDeserializeTest.cs b/tests/Utf8Json.Tests/BassClassDeserializeTest.cs new file mode 100644 index 0000000..e0e1dee --- /dev/null +++ b/tests/Utf8Json.Tests/BassClassDeserializeTest.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace Utf8Json.Tests +{ + public abstract class Base1 + { + public int B1 { get { return _b1; } } + private int _b1 = -1; + } + + public abstract class Base2 : Base1 + { + public int B2 { get { return _b2; } } + private int _b2 = -2; + } + + public class Impl1_2 : Base2 + { + public string Name { get { return name; } } + private string name = "none"; + } + + public class BassClassDeserializeTest + { + [Fact] + public void Deserialize() + { + var json = "{\"_b1\":10,\"_b2\":99,\"name\":\"foobar\"}"; + + var r = JsonSerializer.Deserialize(json, Utf8Json.Resolvers.StandardResolver.AllowPrivate); + + r.B1.Is(10); + r.B2.Is(99); + r.Name.Is("foobar"); + } + } +} From a43f003253fd148067a0c349ce20c04e95de60b9 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Tue, 30 Jan 2018 11:51:40 +0900 Subject: [PATCH 09/12] ready for 1.3.7 --- docs/Utf8Json.AspNetCoreMvcFormatter.nuspec | 6 +- docs/Utf8Json.ImmutableCollection.nuspec | 8 +- docs/Utf8Json.UnityShims.nuspec | 8 +- docs/Utf8Json.nuspec | 2 +- docs/push.bat | 8 +- .../_AssemblyInfo.cs | 4 +- .../_AssemblyInfo.cs | 4 +- .../RuntimeUnitTestToolkit/UnitTestRunner.cs | 1 + .../ProjectSettings/ProjectVersion.txt | 2 +- .../Utf8Json.UnityClient.csproj | 114 +++++++++++++++--- src/Utf8Json.UnityShims/_AssemblyInfo.cs | 4 +- .../Resolvers/DynamicObjectResolver.cs | 7 +- src/Utf8Json/_AssemblyInfo.cs | 4 +- 13 files changed, 126 insertions(+), 46 deletions(-) diff --git a/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec b/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec index 2d9000b..b1cef4a 100644 --- a/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec +++ b/docs/Utf8Json.AspNetCoreMvcFormatter.nuspec @@ -2,7 +2,7 @@ Utf8Json.AspNetCoreMvcFormatter - 1.3.6.1 + 1.3.7 Utf8Json AspNetCoreMvcFormatter neuecc neuecc @@ -13,11 +13,11 @@ Json, Serialization, Formatter, Serializer, Unity, Xamarin, ASPNET - + - + diff --git a/docs/Utf8Json.ImmutableCollection.nuspec b/docs/Utf8Json.ImmutableCollection.nuspec index 3d52de8..33f90d6 100644 --- a/docs/Utf8Json.ImmutableCollection.nuspec +++ b/docs/Utf8Json.ImmutableCollection.nuspec @@ -2,7 +2,7 @@ Utf8Json.ImmutableCollection - 1.3.6.1 + 1.3.7 Utf8Json Extension Resolver for ImmutableCollection neuecc neuecc @@ -12,15 +12,15 @@ Json, Serialization, Formatter, Serializer, Unity, Xamarin - + - + - + diff --git a/docs/Utf8Json.UnityShims.nuspec b/docs/Utf8Json.UnityShims.nuspec index 032b7e4..9eb1494 100644 --- a/docs/Utf8Json.UnityShims.nuspec +++ b/docs/Utf8Json.UnityShims.nuspec @@ -2,7 +2,7 @@ Utf8Json.UnityShims - 1.3.6.1 + 1.3.7 Utf8Json UnityShims neuecc neuecc @@ -12,15 +12,15 @@ Json, Serialization, Formatter, Serializer, Unity, Xamarin - + - + - + diff --git a/docs/Utf8Json.nuspec b/docs/Utf8Json.nuspec index 1531c9f..39c440b 100644 --- a/docs/Utf8Json.nuspec +++ b/docs/Utf8Json.nuspec @@ -2,7 +2,7 @@ Utf8Json - 1.3.6.1 + 1.3.7 Utf8Json neuecc neuecc diff --git a/docs/push.bat b/docs/push.bat index 25fdb0e..dcf7097 100644 --- a/docs/push.bat +++ b/docs/push.bat @@ -1,4 +1,4 @@ -nuget push Utf8Json.1.3.6.1.nupkg -Source https://www.nuget.org/api/v2/package -nuget push Utf8Json.ImmutableCollection.1.3.6.1.nupkg -Source https://www.nuget.org/api/v2/package -nuget push Utf8Json.UnityShims.1.3.6.1.nupkg -Source https://www.nuget.org/api/v2/package -nuget push Utf8Json.AspNetCoreMvcFormatter.1.3.6.1.nupkg -Source https://www.nuget.org/api/v2/package \ No newline at end of file +nuget push Utf8Json.1.3.7.nupkg -Source https://www.nuget.org/api/v2/package +nuget push Utf8Json.ImmutableCollection.1.3.7.nupkg -Source https://www.nuget.org/api/v2/package +nuget push Utf8Json.UnityShims.1.3.7.nupkg -Source https://www.nuget.org/api/v2/package +nuget push Utf8Json.AspNetCoreMvcFormatter.1.3.7.nupkg -Source https://www.nuget.org/api/v2/package \ No newline at end of file diff --git a/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs b/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs index eccd998..498fe71 100644 --- a/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs +++ b/src/Utf8Json.AspNetCoreMvcFormatter/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("899f8b6c-c4c7-4e8b-9875-f61fdfb630bd")] -[assembly: AssemblyVersion("1.3.6.1")] -[assembly: AssemblyFileVersion("1.3.6.1")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.7")] +[assembly: AssemblyFileVersion("1.3.7")] \ No newline at end of file diff --git a/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs b/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs index 40ff535..1add8d1 100644 --- a/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs +++ b/src/Utf8Json.ImmutableCollection/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("2e7ac239-3db1-4772-9f47-5f62abb56ed0")] -[assembly: AssemblyVersion("1.3.6.1")] -[assembly: AssemblyFileVersion("1.3.6.1")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.7")] +[assembly: AssemblyFileVersion("1.3.7")] \ No newline at end of file diff --git a/src/Utf8Json.UnityClient/Assets/Scripts/RuntimeUnitTestToolkit/UnitTestRunner.cs b/src/Utf8Json.UnityClient/Assets/Scripts/RuntimeUnitTestToolkit/UnitTestRunner.cs index 5c896cd..8a46fe5 100644 --- a/src/Utf8Json.UnityClient/Assets/Scripts/RuntimeUnitTestToolkit/UnitTestRunner.cs +++ b/src/Utf8Json.UnityClient/Assets/Scripts/RuntimeUnitTestToolkit/UnitTestRunner.cs @@ -1,5 +1,6 @@  +using System.Reflection; using System; using System.Linq; using System.Collections.Generic; diff --git a/src/Utf8Json.UnityClient/ProjectSettings/ProjectVersion.txt b/src/Utf8Json.UnityClient/ProjectSettings/ProjectVersion.txt index 98d68d3..e6cd1f9 100644 --- a/src/Utf8Json.UnityClient/ProjectSettings/ProjectVersion.txt +++ b/src/Utf8Json.UnityClient/ProjectSettings/ProjectVersion.txt @@ -1 +1 @@ -m_EditorVersion: 2018.1.0b2 +m_EditorVersion: 2017.3.0f3 diff --git a/src/Utf8Json.UnityClient/Utf8Json.UnityClient.csproj b/src/Utf8Json.UnityClient/Utf8Json.UnityClient.csproj index dfd056d..6b241e5 100644 --- a/src/Utf8Json.UnityClient/Utf8Json.UnityClient.csproj +++ b/src/Utf8Json.UnityClient/Utf8Json.UnityClient.csproj @@ -16,7 +16,7 @@ Game:1 StandaloneWindows64:19 - 2017.2.0f3 + 2017.3.0f3 4 @@ -27,7 +27,7 @@ Temp\UnityVS_obj\Debug\ prompt 4 - DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_2_0;UNITY_2017_2;UNITY_2017;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;ENABLE_SPRITE_MASKING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_RMGUI;ENABLE_PACKMAN;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_STYLE_SHEETS;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_SPATIALTRACKING;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE + DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_3_0;UNITY_2017_3;UNITY_2017;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;ENABLE_SPRITE_MASKING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_RMGUI;ENABLE_PACKMAN;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_STYLE_SHEETS;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE true @@ -37,7 +37,7 @@ Temp\UnityVS_obj\Release\ prompt 4 - TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_2_0;UNITY_2017_2;UNITY_2017;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;ENABLE_SPRITE_MASKING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_RMGUI;ENABLE_PACKMAN;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_STYLE_SHEETS;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_SPATIALTRACKING;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE + TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_3_0;UNITY_2017_3;UNITY_2017;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;ENABLE_SPRITE_MASKING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_RMGUI;ENABLE_PACKMAN;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_STYLE_SHEETS;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE true @@ -91,18 +91,6 @@ Library\UnityAssemblies\UnityEngine.IMGUIModule.dll - - Library\UnityAssemblies\UnityEngine.UnityWebRequestModule.dll - - - Library\UnityAssemblies\UnityEngine.UnityWebRequestAudioModule.dll - - - Library\UnityAssemblies\UnityEngine.UnityWebRequestTextureModule.dll - - - Library\UnityAssemblies\UnityEngine.UnityWebRequestWWWModule.dll - Library\UnityAssemblies\UnityEngine.ClusterInputModule.dll @@ -118,9 +106,6 @@ Library\UnityAssemblies\UnityEngine.UnityAnalyticsModule.dll - - Library\UnityAssemblies\UnityEngine.CrashReportingModule.dll - Library\UnityAssemblies\UnityEngine.PerformanceReportingModule.dll @@ -142,9 +127,15 @@ Library\UnityAssemblies\UnityEngine.StyleSheetsModule.dll + + Library\UnityAssemblies\UnityEngine.AssetBundleModule.dll + Library\UnityAssemblies\UnityEngine.AudioModule.dll + + Library\UnityAssemblies\UnityEngine.CrashReportingModule.dll + Library\UnityAssemblies\UnityEngine.GameCenterModule.dll @@ -169,15 +160,33 @@ Library\UnityAssemblies\UnityEngine.ScreenCaptureModule.dll + + Library\UnityAssemblies\UnityEngine.SharedInternalsModule.dll + Library\UnityAssemblies\UnityEngine.SpriteMaskModule.dll + + Library\UnityAssemblies\UnityEngine.SpriteShapeModule.dll + Library\UnityAssemblies\UnityEngine.TerrainModule.dll Library\UnityAssemblies\UnityEngine.TilemapModule.dll + + Library\UnityAssemblies\UnityEngine.UnityWebRequestModule.dll + + + Library\UnityAssemblies\UnityEngine.UnityWebRequestAudioModule.dll + + + Library\UnityAssemblies\UnityEngine.UnityWebRequestTextureModule.dll + + + Library\UnityAssemblies\UnityEngine.UnityWebRequestWWWModule.dll + Library\UnityAssemblies\UnityEngine.VideoModule.dll @@ -187,9 +196,18 @@ Library\UnityAssemblies\UnityEngine.UI.dll + + Library\UnityAssemblies\UnityEditor.UI.dll + Library\UnityAssemblies\UnityEngine.Networking.dll + + Library\UnityAssemblies\UnityEditor.Networking.dll + + + Library\UnityAssemblies\UnityEditor.TestRunner.dll + Library\UnityAssemblies\UnityEngine.TestRunner.dll @@ -199,24 +217,84 @@ Library\UnityAssemblies\UnityEngine.Timeline.dll + + Library\UnityAssemblies\UnityEditor.Timeline.dll + + + Library\UnityAssemblies\UnityEditor.TreeEditor.dll + Library\UnityAssemblies\UnityEngine.UIAutomation.dll + + Library\UnityAssemblies\UnityEditor.UIAutomation.dll + + + Library\UnityAssemblies\UnityEditor.GoogleAudioSpatializer.dll + Library\UnityAssemblies\UnityEngine.GoogleAudioSpatializer.dll + + Library\UnityAssemblies\UnityEditor.HoloLens.dll + Library\UnityAssemblies\UnityEngine.HoloLens.dll + + Library\UnityAssemblies\UnityEditor.SpatialTracking.dll + Library\UnityAssemblies\UnityEngine.SpatialTracking.dll + + Library\UnityAssemblies\UnityEditor.VR.dll + + + Library\UnityAssemblies\UnityEditor.Graphs.dll + + + Library\UnityAssemblies\UnityEditor.Android.Extensions.dll + + + Library\UnityAssemblies\UnityEditor.iOS.Extensions.dll + + + Library\UnityAssemblies\UnityEditor.WSA.Extensions.dll + + + Library\UnityAssemblies\UnityEditor.WindowsStandalone.Extensions.dll + + + Library\UnityAssemblies\SyntaxTree.VisualStudio.Unity.Bridge.dll + + + Library\UnityAssemblies\UnityEngine.Advertisements.dll + + + Library\UnityAssemblies\UnityEditor.Advertisements.dll + Library\UnityAssemblies\UnityEngine.Analytics.dll + + Library\UnityAssemblies\UnityEditor.Analytics.dll + Library\UnityAssemblies\UnityEngine.Purchasing.dll + + Library\UnityAssemblies\UnityEditor.Purchasing.dll + + + Library\UnityAssemblies\UnityEngine.StandardEvents.dll + + + Library\UnityAssemblies\UnityEditor.iOS.Extensions.Xcode.dll + + + Library\UnityAssemblies\UnityEditor.iOS.Extensions.Common.dll + diff --git a/src/Utf8Json.UnityShims/_AssemblyInfo.cs b/src/Utf8Json.UnityShims/_AssemblyInfo.cs index aecb018..484e3bd 100644 --- a/src/Utf8Json.UnityShims/_AssemblyInfo.cs +++ b/src/Utf8Json.UnityShims/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("bf5d0a42-70b7-417d-af8c-2f7e073057e2")] -[assembly: AssemblyVersion("1.3.6.1")] -[assembly: AssemblyFileVersion("1.3.6.1")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.7")] +[assembly: AssemblyFileVersion("1.3.7")] \ No newline at end of file diff --git a/src/Utf8Json/Resolvers/DynamicObjectResolver.cs b/src/Utf8Json/Resolvers/DynamicObjectResolver.cs index 47acd8b..8ba36e0 100644 --- a/src/Utf8Json/Resolvers/DynamicObjectResolver.cs +++ b/src/Utf8Json/Resolvers/DynamicObjectResolver.cs @@ -927,8 +927,8 @@ static void BuildSerialize(Type type, MetaType info, ILGenerator il, Action emit il.EmitLdloc(exceptionType); il.Emit(OpCodes.Ldtoken, typeof(Exception)); il.EmitCall(EmitInfo.GetTypeFromHandle); - il.EmitCall(EmitInfo.TypeOpInequality); - il.Emit(OpCodes.Brfalse, elseBody); + il.EmitCall(EmitInfo.TypeEquals); + il.Emit(OpCodes.Brtrue, elseBody); il.EmitLdloc(exceptionType); argWriter.EmitLoad(); @@ -1499,7 +1499,8 @@ internal static class EmitInfo public static readonly MethodInfo GetUninitializedObject = ExpressionUtility.GetMethodInfo(() => System.Runtime.Serialization.FormatterServices.GetUninitializedObject(default(Type))); public static readonly MethodInfo GetTypeMethod = ExpressionUtility.GetMethodInfo((object o) => o.GetType()); - public static readonly MethodInfo TypeOpInequality = typeof(Type).GetTypeInfo().GetRuntimeMethods().First(x => x.Name == "op_Inequality"); + public static readonly MethodInfo TypeEquals = ExpressionUtility.GetMethodInfo((Type t) => t.Equals(default(Type))); + public static readonly MethodInfo NongenericSerialize = ExpressionUtility.GetMethodInfo(writer => JsonSerializer.NonGeneric.Serialize(default(Type), ref writer, default(object), default(IJsonFormatterResolver))); public static MethodInfo Serialize(Type type) diff --git a/src/Utf8Json/_AssemblyInfo.cs b/src/Utf8Json/_AssemblyInfo.cs index 1f96370..2e407ff 100644 --- a/src/Utf8Json/_AssemblyInfo.cs +++ b/src/Utf8Json/_AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("929e3779-4c3a-42a3-bc72-3d77511e988f")] -[assembly: AssemblyVersion("1.3.6.1")] -[assembly: AssemblyFileVersion("1.3.6.1")] +[assembly: AssemblyVersion("1.3.7")] +[assembly: AssemblyFileVersion("1.3.7")] From 4572486dd377c611542fb21abb690ac8fecf3416 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Wed, 31 Jan 2018 11:13:22 +0900 Subject: [PATCH 10/12] fix allowprivate issue on Unity #48 --- .../Assembly-CSharp.csproj | 1 + .../Assets/Scripts/Tests/PirvateTest.cs | 37 ++++ .../Assets/Scripts/Tests/_Loader.cs | 1 + .../Scripts/Utf8Json/Shims/Reflection.cs | 18 +- .../ProjectSettings/ProjectVersion.txt | 2 +- .../Utf8Json.UnityClient.csproj | 206 +++++++++++------- 6 files changed, 180 insertions(+), 85 deletions(-) create mode 100644 src/Utf8Json.UnityClient/Assets/Scripts/Tests/PirvateTest.cs diff --git a/src/Utf8Json.UnityClient/Assembly-CSharp.csproj b/src/Utf8Json.UnityClient/Assembly-CSharp.csproj index 8d369e0..0c58433 100644 --- a/src/Utf8Json.UnityClient/Assembly-CSharp.csproj +++ b/src/Utf8Json.UnityClient/Assembly-CSharp.csproj @@ -55,6 +55,7 @@ + diff --git a/src/Utf8Json.UnityClient/Assets/Scripts/Tests/PirvateTest.cs b/src/Utf8Json.UnityClient/Assets/Scripts/Tests/PirvateTest.cs new file mode 100644 index 0000000..e52aff1 --- /dev/null +++ b/src/Utf8Json.UnityClient/Assets/Scripts/Tests/PirvateTest.cs @@ -0,0 +1,37 @@ +using UnityEngine; +using RuntimeUnitTestToolkit; +using System.Collections; + +using System.Collections.Generic; +using System; +using Utf8Json; +using System.Text; +using System.Linq; + +namespace Utf8Json.UnityClient.Tests +{ + public class BassPrivate + { + int x = 0; + + public int GetX() + { + return x; + } + } + + public class Inherit: BassPrivate + { + public int Y; + } + + public class PrivateTest + { + public void CanSerialize() + { + var foo = JsonSerializer.Deserialize("{\"x\":10,\"Y\":99}", Utf8Json.Resolvers.StandardResolver.AllowPrivate); + foo.Y.Is(99); + foo.GetX().Is(10); + } + } +} \ No newline at end of file diff --git a/src/Utf8Json.UnityClient/Assets/Scripts/Tests/_Loader.cs b/src/Utf8Json.UnityClient/Assets/Scripts/Tests/_Loader.cs index b9ab80f..5606d1c 100644 --- a/src/Utf8Json.UnityClient/Assets/Scripts/Tests/_Loader.cs +++ b/src/Utf8Json.UnityClient/Assets/Scripts/Tests/_Loader.cs @@ -13,6 +13,7 @@ public static class UnitTestLoader public static void Register() { UnitTest.RegisterAllMethods(); + UnitTest.RegisterAllMethods(); //#if !UNITY_METRO diff --git a/src/Utf8Json.UnityClient/Assets/Scripts/Utf8Json/Shims/Reflection.cs b/src/Utf8Json.UnityClient/Assets/Scripts/Utf8Json/Shims/Reflection.cs index 0bd0d52..b3e9e66 100644 --- a/src/Utf8Json.UnityClient/Assets/Scripts/Utf8Json/Shims/Reflection.cs +++ b/src/Utf8Json.UnityClient/Assets/Scripts/Utf8Json/Shims/Reflection.cs @@ -191,6 +191,10 @@ internal static class ReflectionExtensions #if !NET_4_6 + static readonly BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance + | BindingFlags.GetField | BindingFlags.GetProperty | BindingFlags.SetField | BindingFlags.SetProperty + | BindingFlags.InvokeMethod; + public static TypeInfo GetTypeInfo(this Type type) { return new TypeInfo(type); @@ -203,37 +207,37 @@ public static TypeInfo CreateTypeInfo(this TypeBuilder type) public static MethodInfo GetRuntimeMethod(this Type type, string name, Type[] types) { - return type.GetMethod(name, types); + return type.GetMethod(name, types); // no use flags. } public static MethodInfo GetRuntimeMethod(this Type type, string name) { - return type.GetMethod(name); + return type.GetMethod(name); // no use flags. } public static MethodInfo[] GetRuntimeMethods(this Type type) { - return type.GetMethods(); + return type.GetMethods(flags); } public static PropertyInfo GetRuntimeProperty(this Type type, string name) { - return type.GetProperty(name); + return type.GetProperty(name, flags); } public static PropertyInfo[] GetRuntimeProperties(this Type type) { - return type.GetProperties(); + return type.GetProperties(flags); } public static FieldInfo GetRuntimeField(this Type type, string name) { - return type.GetField(name); + return type.GetField(name, flags); } public static FieldInfo[] GetRuntimeFields(this Type type) { - return type.GetFields(); + return type.GetFields(flags); } public static T GetCustomAttribute(this FieldInfo type, bool inherit) diff --git a/src/Utf8Json.UnityClient/ProjectSettings/ProjectVersion.txt b/src/Utf8Json.UnityClient/ProjectSettings/ProjectVersion.txt index e6cd1f9..98d68d3 100644 --- a/src/Utf8Json.UnityClient/ProjectSettings/ProjectVersion.txt +++ b/src/Utf8Json.UnityClient/ProjectSettings/ProjectVersion.txt @@ -1 +1 @@ -m_EditorVersion: 2017.3.0f3 +m_EditorVersion: 2018.1.0b2 diff --git a/src/Utf8Json.UnityClient/Utf8Json.UnityClient.csproj b/src/Utf8Json.UnityClient/Utf8Json.UnityClient.csproj index 6b241e5..f13b796 100644 --- a/src/Utf8Json.UnityClient/Utf8Json.UnityClient.csproj +++ b/src/Utf8Json.UnityClient/Utf8Json.UnityClient.csproj @@ -16,7 +16,7 @@ Game:1 StandaloneWindows64:19 - 2017.3.0f3 + 2018.1.0b2 4 @@ -27,7 +27,7 @@ Temp\UnityVS_obj\Debug\ prompt 4 - DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_3_0;UNITY_2017_3;UNITY_2017;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;ENABLE_SPRITE_MASKING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_RMGUI;ENABLE_PACKMAN;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_STYLE_SHEETS;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE + DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2018_1_OR_NEWER;UNITY_2018_1_0;UNITY_2018_1;UNITY_2018;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_MANAGED_JOBS;ENABLE_MANAGED_TRANSFORM_JOBS;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_PACKMAN;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_OUT_OF_PROCESS_CRASH_HANDLER;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_UNITY_COLLECTIONS_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE true @@ -37,7 +37,7 @@ Temp\UnityVS_obj\Release\ prompt 4 - TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2017_3_0;UNITY_2017_3;UNITY_2017;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;ENABLE_SPRITE_MASKING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_RMGUI;ENABLE_PACKMAN;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_STYLE_SHEETS;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE + TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2017_3_OR_NEWER;UNITY_2018_1_OR_NEWER;UNITY_2018_1_0;UNITY_2018_1;UNITY_2018;PLATFORM_ARCH_64;UNITY_64;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_GRID;ENABLE_TILEMAP;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_DIRECTOR;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_COLLAB_SOFTLOCKS;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_USE_WEBREQUEST;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_HUB;ENABLE_EDITOR_HUB_LICENSE;ENABLE_WEBSOCKET_CLIENT;ENABLE_DIRECTOR_AUDIO;ENABLE_DIRECTOR_TEXTURE;ENABLE_TIMELINE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_MANAGED_JOBS;ENABLE_MANAGED_TRANSFORM_JOBS;INCLUDE_DYNAMIC_GI;INCLUDE_GI;ENABLE_MONO_BDWGC;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_VIDEO;ENABLE_PACKMAN;ENABLE_CUSTOM_RENDER_TEXTURE;ENABLE_LOCALIZATION;PLATFORM_STANDALONE_WIN;PLATFORM_STANDALONE;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_OUT_OF_PROCESS_CRASH_HANDLER;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_AR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_UNITY_COLLECTIONS_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE true @@ -49,47 +49,35 @@ - - Library\UnityAssemblies\UnityEditor.dll - Library\UnityAssemblies\UnityEngine.dll - - Library\UnityAssemblies\UnityEngine.CoreModule.dll + + Library\UnityAssemblies\UnityEngine.AIModule.dll + + + Library\UnityAssemblies\UnityEngine.ARModule.dll Library\UnityAssemblies\UnityEngine.AccessibilityModule.dll - - Library\UnityAssemblies\UnityEngine.ParticleSystemModule.dll - - - Library\UnityAssemblies\UnityEngine.PhysicsModule.dll - - - Library\UnityAssemblies\UnityEngine.VehiclesModule.dll - - - Library\UnityAssemblies\UnityEngine.ClothModule.dll - - - Library\UnityAssemblies\UnityEngine.AIModule.dll - Library\UnityAssemblies\UnityEngine.AnimationModule.dll - - Library\UnityAssemblies\UnityEngine.TextRenderingModule.dll + + Library\UnityAssemblies\UnityEngine.AssetBundleModule.dll - - Library\UnityAssemblies\UnityEngine.UIModule.dll + + Library\UnityAssemblies\UnityEngine.AudioModule.dll - - Library\UnityAssemblies\UnityEngine.TerrainPhysicsModule.dll + + Library\UnityAssemblies\UnityEngine.BaselibModule.dll - - Library\UnityAssemblies\UnityEngine.IMGUIModule.dll + + Library\UnityAssemblies\UnityEngine.ClothModule.dll + + + Library\UnityAssemblies\UnityEngine.CloudWebServicesModule.dll Library\UnityAssemblies\UnityEngine.ClusterInputModule.dll @@ -97,44 +85,17 @@ Library\UnityAssemblies\UnityEngine.ClusterRendererModule.dll - - Library\UnityAssemblies\UnityEngine.UNETModule.dll + + Library\UnityAssemblies\UnityEngine.CoreModule.dll + + + Library\UnityAssemblies\UnityEngine.CrashReportingModule.dll Library\UnityAssemblies\UnityEngine.DirectorModule.dll - - Library\UnityAssemblies\UnityEngine.UnityAnalyticsModule.dll - - - Library\UnityAssemblies\UnityEngine.PerformanceReportingModule.dll - - - Library\UnityAssemblies\UnityEngine.UnityConnectModule.dll - - - Library\UnityAssemblies\UnityEngine.WebModule.dll - - - Library\UnityAssemblies\UnityEngine.ARModule.dll - - - Library\UnityAssemblies\UnityEngine.VRModule.dll - - - Library\UnityAssemblies\UnityEngine.UIElementsModule.dll - - - Library\UnityAssemblies\UnityEngine.StyleSheetsModule.dll - - - Library\UnityAssemblies\UnityEngine.AssetBundleModule.dll - - - Library\UnityAssemblies\UnityEngine.AudioModule.dll - - - Library\UnityAssemblies\UnityEngine.CrashReportingModule.dll + + Library\UnityAssemblies\UnityEngine.FacebookModule.dll Library\UnityAssemblies\UnityEngine.GameCenterModule.dll @@ -142,6 +103,12 @@ Library\UnityAssemblies\UnityEngine.GridModule.dll + + Library\UnityAssemblies\UnityEngine.HotReloadModule.dll + + + Library\UnityAssemblies\UnityEngine.IMGUIModule.dll + Library\UnityAssemblies\UnityEngine.ImageConversionModule.dll @@ -151,9 +118,18 @@ Library\UnityAssemblies\UnityEngine.JSONSerializeModule.dll + + Library\UnityAssemblies\UnityEngine.ParticleSystemModule.dll + Library\UnityAssemblies\UnityEngine.ParticlesLegacyModule.dll + + Library\UnityAssemblies\UnityEngine.PerformanceReportingModule.dll + + + Library\UnityAssemblies\UnityEngine.PhysicsModule.dll + Library\UnityAssemblies\UnityEngine.Physics2DModule.dll @@ -163,21 +139,63 @@ Library\UnityAssemblies\UnityEngine.SharedInternalsModule.dll + + Library\UnityAssemblies\UnityEngine.SpatialTrackingModule.dll + Library\UnityAssemblies\UnityEngine.SpriteMaskModule.dll Library\UnityAssemblies\UnityEngine.SpriteShapeModule.dll + + Library\UnityAssemblies\UnityEngine.StyleSheetsModule.dll + + + Library\UnityAssemblies\UnityEngine.SubstanceModule.dll + + + Library\UnityAssemblies\UnityEngine.TLSModule.dll + Library\UnityAssemblies\UnityEngine.TerrainModule.dll + + Library\UnityAssemblies\UnityEngine.TerrainPhysicsModule.dll + + + Library\UnityAssemblies\UnityEngine.TextRenderingModule.dll + Library\UnityAssemblies\UnityEngine.TilemapModule.dll + + Library\UnityAssemblies\UnityEngine.TimelineModule.dll + + + Library\UnityAssemblies\UnityEngine.UIModule.dll + + + Library\UnityAssemblies\UnityEngine.UIElementsModule.dll + + + Library\UnityAssemblies\UnityEngine.UNETModule.dll + + + Library\UnityAssemblies\UnityEngine.UmbraModule.dll + + + Library\UnityAssemblies\UnityEngine.UnityAnalyticsModule.dll + + + Library\UnityAssemblies\UnityEngine.UnityConnectModule.dll + Library\UnityAssemblies\UnityEngine.UnityWebRequestModule.dll + + Library\UnityAssemblies\UnityEngine.UnityWebRequestAssetBundleModule.dll + Library\UnityAssemblies\UnityEngine.UnityWebRequestAudioModule.dll @@ -187,12 +205,30 @@ Library\UnityAssemblies\UnityEngine.UnityWebRequestWWWModule.dll + + Library\UnityAssemblies\UnityEngine.VRModule.dll + + + Library\UnityAssemblies\UnityEngine.VehiclesModule.dll + Library\UnityAssemblies\UnityEngine.VideoModule.dll + + Library\UnityAssemblies\UnityEngine.WebModule.dll + Library\UnityAssemblies\UnityEngine.WindModule.dll + + Library\UnityAssemblies\UnityEngine.XRModule.dll + + + Library\UnityAssemblies\UnityEditor.dll + + + Library\UnityAssemblies\Unity.Locator.dll + Library\UnityAssemblies\UnityEngine.UI.dll @@ -205,15 +241,6 @@ Library\UnityAssemblies\UnityEditor.Networking.dll - - Library\UnityAssemblies\UnityEditor.TestRunner.dll - - - Library\UnityAssemblies\UnityEngine.TestRunner.dll - - - Library\UnityAssemblies\nunit.framework.dll - Library\UnityAssemblies\UnityEngine.Timeline.dll @@ -286,21 +313,46 @@ Library\UnityAssemblies\UnityEditor.Purchasing.dll - - Library\UnityAssemblies\UnityEngine.StandardEvents.dll - Library\UnityAssemblies\UnityEditor.iOS.Extensions.Xcode.dll Library\UnityAssemblies\UnityEditor.iOS.Extensions.Common.dll + + Library\UnityAssemblies\mscorlib.dll + + + Library\UnityAssemblies\System.dll + + + Library\UnityAssemblies\System.Core.dll + + + Library\UnityAssemblies\System.Runtime.Serialization.dll + + + Library\UnityAssemblies\System.Xml.dll + + + Library\UnityAssemblies\System.Xml.Linq.dll + + + Library\UnityAssemblies\UnityScript.dll + + + Library\UnityAssemblies\UnityScript.Lang.dll + + + Library\UnityAssemblies\Boo.Lang.dll + + From 7f7d6e30b65e56e250baa49f5becba64730e5227 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai Date: Fri, 9 Mar 2018 23:51:57 +0900 Subject: [PATCH 11/12] fix PrimitiveObjectFormatter.Serializer does not emit comma when value is collection or dictionary #61 --- .../Formatters/PrimitiveObjectFormatter.cs | 5 ++-- .../PrimitiveObjectFormatterTest.cs | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/Utf8Json.Tests/PrimitiveObjectFormatterTest.cs diff --git a/src/Utf8Json/Formatters/PrimitiveObjectFormatter.cs b/src/Utf8Json/Formatters/PrimitiveObjectFormatter.cs index 2afaaa4..48c18e4 100644 --- a/src/Utf8Json/Formatters/PrimitiveObjectFormatter.cs +++ b/src/Utf8Json/Formatters/PrimitiveObjectFormatter.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using Utf8Json.Internal; namespace Utf8Json.Formatters { @@ -76,7 +75,7 @@ public void Serialize(ref JsonWriter writer, object value, IJsonFormatterResolve writer.WriteBeginObject(); foreach (DictionaryEntry item in dict) { - if (count != 0) writer.WriteValueSeparator(); + if (count++ != 0) writer.WriteValueSeparator(); writer.WritePropertyName((string)item.Key); Serialize(ref writer, item.Value, formatterResolver); } @@ -91,7 +90,7 @@ public void Serialize(ref JsonWriter writer, object value, IJsonFormatterResolve writer.WriteBeginArray(); foreach (var item in collection) { - if (count != 0) writer.WriteValueSeparator(); + if (count++ != 0) writer.WriteValueSeparator(); Serialize(ref writer, item, formatterResolver); } writer.WriteEndArray(); diff --git a/tests/Utf8Json.Tests/PrimitiveObjectFormatterTest.cs b/tests/Utf8Json.Tests/PrimitiveObjectFormatterTest.cs new file mode 100644 index 0000000..7629893 --- /dev/null +++ b/tests/Utf8Json.Tests/PrimitiveObjectFormatterTest.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Utf8Json.Formatters; +using Xunit; + +namespace Utf8Json.Tests +{ + public class PrimitiveObjectFormatterTest + { + [Fact] + public void Collection() + { + var jw = new JsonWriter(); + PrimitiveObjectFormatter.Default.Serialize(ref jw, new[] { "foo", "bar", "baz" }, null); + + jw.ToString().Is("[\"foo\",\"bar\",\"baz\"]"); + } + + [Fact] + public void Map() + { + var jw = new JsonWriter(); + PrimitiveObjectFormatter.Default.Serialize(ref jw, new Dictionary { { "foo", 10 }, { "bar", 99 }, { "baz", 100 } }, null); + + jw.ToString().Is("{\"foo\":10,\"bar\":99,\"baz\":100}"); + } + } +} From cd2e6b0e15394ea1e3ba08612c6a6858223be776 Mon Sep 17 00:00:00 2001 From: izm Date: Thu, 26 Apr 2018 20:57:43 +0900 Subject: [PATCH 12/12] Update README.md fix compile error in readme codesample --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b35d189..1a707fa 100644 --- a/README.md +++ b/README.md @@ -928,7 +928,7 @@ Utf8Json.Resolvers.CompositeResolver.RegisterAndSetAsDefault( Utf8Json.Resolvers.GeneratedResolver.Instance, // set StandardResolver or your use resolver chain - Utf8Json.StandardResolver.Default, + Utf8Json.Resolvers.StandardResolver.Default, ); ```