holopy3/Assets/UniGLTF/UniJSON/README.md
Lena Biresch 490ef558ef CleanUp
2021-01-28 13:07:52 +01:00

1.3 KiB

UniJSON

JSON serializer and deserializer and schema utilities for Unity(.Net3.5)

JSON

JSON Schema

JSON Patch

ToDo

  • anyOf to enum
  • string.pattern
  • enum.values
  • array.items
  • object.required
  • object.dependencies
  • object.additionalProperties
  • default value

Example

[Serializable]
public class glTFSparseIndices
{
    [JsonSchema(Minimum = 0)]
    public int bufferView;

    [JsonSchema(Minimum = 0)]
    public int byteOffset;

    [JsonSchema(EnumSerializationType = EnumSerializationType.AsInt)]
    public glComponentType componentType;

    // empty schemas
    public object extensions;
    public object extras;
}


[Test]
public void AccessorSparseIndices()
{
    // from JSON schema
    var path = Path.GetFullPath(Application.dataPath + "/../glTF/specification/2.0/schema");
    var SchemaDir = new FileSystemAccessor(path);
    var fromSchema = JsonSchema.ParseFromPath(SchemaDir.Get("accessor.sparse.indices.schema.json"));

    // from C# type definition
    var fromClass = JsonSchema.FromType<glTFSparseIndices>();

    Assert.AreEqual(fromSchema, fromClass);
}