diff --git a/src/MessagePack/Formatters/PrimitiveObjectFormatter.cs b/src/MessagePack/Formatters/PrimitiveObjectFormatter.cs
index 553251de..eefa464a 100644
--- a/src/MessagePack/Formatters/PrimitiveObjectFormatter.cs
+++ b/src/MessagePack/Formatters/PrimitiveObjectFormatter.cs
@@ -32,6 +32,18 @@ namespace MessagePack.Formatters
}
+ public static bool IsSupportedType(Type type, TypeInfo typeInfo, object value)
+ {
+ if (value == null) return true;
+ if (typeToJumpCode.ContainsKey(type)) return true;
+ if (typeInfo.IsEnum) return true;
+
+ if (value is System.Collections.IDictionary) return true;
+ if (value is System.Collections.ICollection) return true;
+
+ return false;
+ }
+
public int Serialize(ref byte[] bytes, int offset, object value, IFormatterResolver formatterResolver)
{
if (value == null)
diff --git a/src/MessagePack/Resolvers/DynamicObjectResolver.cs b/src/MessagePack/Resolvers/DynamicObjectResolver.cs
index a03cbec0..6e68e96f 100644
--- a/src/MessagePack/Resolvers/DynamicObjectResolver.cs
+++ b/src/MessagePack/Resolvers/DynamicObjectResolver.cs
@@ -110,6 +110,11 @@ namespace MessagePack.Resolvers
static FormatterCache()
{
+ if (typeof(T) == typeof(object))
+ {
+ return;
+ }
+
var ti = typeof(T).GetTypeInfo();
if (ti.IsNullable())
{
diff --git a/src/MessagePack/Resolvers/StandardResolver.cs b/src/MessagePack/Resolvers/StandardResolver.cs
index bd489e1f..37baa0d9 100644
--- a/src/MessagePack/Resolvers/StandardResolver.cs
+++ b/src/MessagePack/Resolvers/StandardResolver.cs
@@ -1,4 +1,11 @@
using MessagePack.Formatters;
+using System.Linq;
+using MessagePack.Internal;
+using System;
+using System.Reflection;
+using System.Collections.Generic;
+using MessagePack.Resolvers;
+using System.Linq.Expressions;
namespace MessagePack.Resolvers
{
@@ -65,8 +72,26 @@ namespace MessagePack.Resolvers
static readonly IFormatterResolver[] resolvers = new[]
{
- StandardResolver.Instance,
+ BuiltinResolver.Instance, // Try Builtin
+
+ AttributeFormatterResolver.Instance, // Try use [MessagePackFormatter]
+
+#if !NETSTANDARD1_4
+ MessagePack.Unity.UnityResolver.Instance,
+#endif
+
+#if !ENABLE_IL2CPP
+
+ DynamicEnumResolver.Instance, // Try Enum
+ DynamicGenericResolver.Instance, // Try Array, Tuple, Collection
+ DynamicUnionResolver.Instance, // Try Union(Interface)
+ DynamicObjectResolver.Instance, // Try Object
+#endif
+
DynamicContractlessObjectResolver.Instance,
+
+ // finally, try primitive -> dynamic contractless
+ DynamicObjectFallbackResolver.Instance
};
ContractlessStandardResolver()
@@ -96,4 +121,110 @@ namespace MessagePack.Resolvers
}
}
}
+}
+
+namespace MessagePack.Internal
+{
+ ///
+ /// In `object`, when serializing resolve by concrete type and when deserializing use primitive.
+ ///
+ internal class DynamicObjectFallbackResolver : IFormatterResolver
+ {
+ public static IFormatterResolver Instance = new DynamicObjectFallbackResolver();
+
+ DynamicObjectFallbackResolver()
+ {
+
+ }
+
+ public IMessagePackFormatter GetFormatter()
+ {
+ return FormatterCache.formatter;
+ }
+
+ static class FormatterCache
+ {
+ public static readonly IMessagePackFormatter formatter;
+
+ static FormatterCache()
+ {
+ formatter = (typeof(T) == typeof(object))
+ ? (IMessagePackFormatter)(object)DynamicObjectFallbackResolverFormatter.Instance
+ : null;
+ }
+ }
+ }
+
+ internal class DynamicObjectFallbackResolverFormatter : IMessagePackFormatter