umm / cafu_kvs

:green_book: Simple file based key value store system
MIT License
0 stars 0 forks source link

JsonUtility doesn't support serialization of ScriptableObject #9

Closed milkcocoa closed 6 years ago

milkcocoa commented 6 years ago

The following error is raised at ScriptableObjectSaveLoadTest.cs.

ScriptableObjectSaveLoadTest (0.059s)
---
System.ArgumentException : Cannot deserialize JSON to new instances of type 'SampleScriptableEntity.'
---
at (wrapper managed-to-native) UnityEngine.JsonUtility.FromJson(string,System.Type)
  at UnityEngine.JsonUtility.FromJson[T] (System.String json) [0x0000c] in /Users/builduser/buildslave/unity/build/artifacts/generated/bindings_old/common/JSONSerialize/JsonUtilityBindings.gen.cs:25 
  at CAFU.KeyValueStore.Utility.JsonUtilitySerializer.Deserialize[TValue] (System.String text) [0x00002] in /Users/shu/Documents/Works/KidsStar/cafu_kvs/Assets/Scripts/Utility/JsonUtilitySerializer.cs:14 
  at CAFU.KeyValueStore.Data.DataStore.KeyValueDataStore.GetEntity[TEntity] (System.String key) [0x00033] in /Users/shu/Documents/Works/KidsStar/cafu_kvs/Assets/Scripts/Data/DataStore/IKeyValueDataStore.cs:106 
  at CAFU.KeyValueStore.Data.DataStore.KeyValueDataStoreTest.ScriptableObjectSaveLoadTest () [0x0005a] in /Users/shu/Documents/Works/KidsStar/cafu_kvs/Assets/Tests/EditMode/Scripts/Data/KeyValueDataStoreTest.cs:96 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <f826c2584fc94ec19a48a6576640bdc5>:0

According to the source code, JsonUtility seems not to support serialization of ScriptableObject. https://github.com/Unity-Technologies/UnityCsReference/blob/master/Modules/JSONSerialize/Public/JsonUtility.bindings.cs

mattak commented 6 years ago

Sorry, I forgot to removing the ScriptableObject serialization test.

It was created for the other project's json serialization, but now the problem was solved by using pure c# object (eliminating the reference of ScriptableObject). So there is no problem to removing the code.

Thanks!

milkcocoa commented 6 years ago

Can we remove JsonConvertSerializer and dependency on umm@json_net?

If so, I will do that.

mattak commented 6 years ago

Thanks! No problem!