diff --git a/Assets/VRM/UniJSON/Scripts/Json/JsonSchema.cs b/Assets/VRM/UniJSON/Scripts/Json/JsonSchema.cs index be73d4102..1957c4119 100644 --- a/Assets/VRM/UniJSON/Scripts/Json/JsonSchema.cs +++ b/Assets/VRM/UniJSON/Scripts/Json/JsonSchema.cs @@ -58,6 +58,7 @@ namespace UniJSON public bool SkipComparison { get; set; } public object ExplicitIgnorableValue { private get; set; } + public int ExplicitIgnorableItemLength { private get; set; } public override string ToString() { @@ -179,6 +180,7 @@ namespace UniJSON Validator = validator, SkipComparison = skipComparison, ExplicitIgnorableValue = a.ExplicitIgnorableValue, + ExplicitIgnorableItemLength = a.ExplicitIgnorableItemLength, }; return schema; @@ -386,9 +388,12 @@ namespace UniJSON } #endregion - public void Serialize(IFormatter f, T o) + public void Serialize(IFormatter f, T o, JsonSchemaValidationContext c = null) { - var c = new JsonSchemaValidationContext(o); + if (c == null) + { + c = new JsonSchemaValidationContext(o); + } var ex = Validator.Validate(c, o); if (ex != null) @@ -415,16 +420,22 @@ namespace UniJSON return ExplicitIgnorableValue == null; } + var iter = obj as System.Collections.ICollection; + if (ExplicitIgnorableItemLength != -1 && iter != null) + { + return iter.Count == ExplicitIgnorableItemLength; + } + return obj.Equals(ExplicitIgnorableValue); } } public static class JsonSchemaExtensions { - public static string Serialize(this JsonSchema s, T o) + public static string Serialize(this JsonSchema s, T o, JsonSchemaValidationContext c = null) { var f = new JsonFormatter(); - s.Serialize(f, o); + s.Serialize(f, o, c); return f.ToString(); } } diff --git a/Assets/VRM/UniJSON/Scripts/Json/JsonSchemaAttribute.cs b/Assets/VRM/UniJSON/Scripts/Json/JsonSchemaAttribute.cs index f7ebad56a..4e44ebea2 100644 --- a/Assets/VRM/UniJSON/Scripts/Json/JsonSchemaAttribute.cs +++ b/Assets/VRM/UniJSON/Scripts/Json/JsonSchemaAttribute.cs @@ -61,6 +61,12 @@ namespace UniJSON /// public object ExplicitIgnorableValue; + /// + /// Suppress errors if length of a value of the field which is not required by a schema is matched to this value. + /// This feature will be useful to ignore invalid value which is known. + /// + public int ExplicitIgnorableItemLength = -1; + public void Merge(BaseJsonSchemaAttribute rhs) { if (rhs == null) return;