diff --git a/Assets/VRM/UniJSON/Editor/Tests/Json/JsonSerializerTests.cs b/Assets/VRM/UniJSON/Editor/Tests/Json/JsonSerializerTests.cs index 81206004a..78461370d 100644 --- a/Assets/VRM/UniJSON/Editor/Tests/Json/JsonSerializerTests.cs +++ b/Assets/VRM/UniJSON/Editor/Tests/Json/JsonSerializerTests.cs @@ -1,5 +1,6 @@ #pragma warning disable 0649 using System; +using System.Linq; using NUnit.Framework; using System.Collections.Generic; @@ -145,9 +146,38 @@ namespace UniJSON DeserializeValue(new EnumTest(), "{\"EnumDefault\":0,\"EnumAsInt\":0,\"EnumAsString\":\"Hoge\",\"EnumAsLowerString\":\"hoge\"}"); } - class DictionaryValue + class DictionaryValue: IEquatable { - public Dictionary Dict; + public Dictionary Dict = new Dictionary(); + + public override bool Equals(object obj) + { + var rhs = obj as DictionaryValue; + if (rhs != null) + { + return Equals(rhs); + } + else + { + return base.Equals(obj); + } + } + + public bool Equals(DictionaryValue other) + { + if(Dict==null && other.Dict == null) + { + return true; + } + else if(Dict==null || other.Dict==null) + { + return false; + } + else + { + return Dict.OrderBy(x => x.Key).SequenceEqual(other.Dict.OrderBy(x => x.Key)); + } + } } [Test] diff --git a/Assets/VRM/UniJSON/Scripts/JsonSchemaValidator/JsonDictionaryValidator.cs b/Assets/VRM/UniJSON/Scripts/JsonSchemaValidator/JsonDictionaryValidator.cs index 6b97c1e0c..cf191ebf7 100644 --- a/Assets/VRM/UniJSON/Scripts/JsonSchemaValidator/JsonDictionaryValidator.cs +++ b/Assets/VRM/UniJSON/Scripts/JsonSchemaValidator/JsonDictionaryValidator.cs @@ -276,7 +276,7 @@ namespace UniJSON public void Deserialize(ListTreeNode src, ref V dst) where U : IListTreeItem, IValue { - throw new NotImplementedException(); + src.Deserialize(ref dst); } } diff --git a/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs b/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs index 8fba75208..1150312d2 100644 --- a/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs +++ b/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs @@ -219,10 +219,32 @@ namespace VRM [Test] public void MaterialTest() { - var model = new glTF_VRM_Material(); + var model = new glTF_VRM_Material + { + floatProperties = new Dictionary + { + {"float", 1.0f} + }, + vectorProperties = new Dictionary + { + {"vector", new float[]{0, 1, 2, 3 }} + }, + textureProperties = new Dictionary + { + {"texture", 0} + }, + keywordMap = new Dictionary + { + {"keyword", true} + }, + tagMap = new Dictionary + { + {"tag", "map"} + }, + }; var json = model.ToJson(); - Assert.AreEqual(@"{""renderQueue"":-1,""floatProperties"":{},""vectorProperties"":{},""textureProperties"":{},""keywordMap"":{},""tagMap"":{}}", json); + Assert.AreEqual(@"{""renderQueue"":-1,""floatProperties"":{""float"":1},""vectorProperties"":{""vector"":[0,1,2,3]},""textureProperties"":{""texture"":0},""keywordMap"":{""keyword"":true},""tagMap"":{""tag"":""map""}}", json); Debug.Log(json); var c = new JsonSchemaValidationContext("") @@ -231,7 +253,12 @@ namespace VRM }; var json2 = JsonSchema.FromType().Serialize(model, c); // NOTE: New serializer outputs values which will not be used... - Assert.AreEqual(json,json2); + Assert.AreEqual(json, json2); + + // deserialize + var deserialized = default(glTF_VRM_Material); + json.ParseAsJson().Deserialize(ref deserialized); + Assert.AreEqual(1, deserialized.floatProperties.Count); } [Test]