Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator thinks integers should be 32-bits? Need very large integers. Larger than Long should be handled as well #31

Closed
coderextreme opened this issue Apr 3, 2016 · 3 comments

Comments

@coderextreme
Copy link

Schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "JSON Schema X3D V3.3",
    "description": "Experimental JSON Schema for X3D V3.3 ",
    "type": "object",
    "properties": {
        "PixelTexture": {
            "type": "object",
            "properties": {
                "@image": {
                    "type": "array",
                    "minItems": 3,
                    "items": [
                        {
                            "type": "integer",
                            "default": 0
                        },
                        {
                            "type": "integer",
                            "default": 0
                        },
                        {
                            "type": "integer",
                            "default": 0
                        }
                    ],
                    "additionalItems": {
                        "type": "integer"
                    }
                }
            }
        }
    }
}

JSON:

{ "PixelTexture":
{
"@image":[4278190335,4278190207, 45]
}
}

Errors produced (from my code:)

json-schema Validation error org.everit.json.schema.ValidationException: #/PixelTexture/@image/0: expected type: Integer, found: Long image.json
json-schema Validation error org.everit.json.schema.ValidationException: #/PixelTexture/@image/1: expected type: Integer, found: Long image.json

@coderextreme
Copy link
Author

Also, this JSON with the above schema

{ "PixelTexture":
{
"@image":[4278190335,4278190207, 999999999999999999999999999999999999999999999999999999999999999999999999999999999]
}
}

Errors:
json-schema Validation error org.everit.json.schema.ValidationException: #/PixelTexture/@image/0: expected type: Integer, found: Long image.json
json-schema Validation error org.everit.json.schema.ValidationException: #/PixelTexture/@image/1: expected type: Integer, found: Long image.json
json-schema Validation error org.everit.json.schema.ValidationException: #/PixelTexture/@image/2: expected type: Number, found: String image.json

erosb added a commit to erosb/everit-json-schema that referenced this issue Apr 3, 2016
erosb added a commit to erosb/everit-json-schema that referenced this issue Apr 3, 2016
@coderextreme
Copy link
Author

Here's a patch for the first one. The second one might be a problem with org.json:

diff --git a/core/src/main/java/org/everit/json/schema/NumberSchema.java b/core/src/main/java/org/everit/json/schema/NumberSchema.java
index 9f5ec10..1185739 100644
--- a/core/src/main/java/org/everit/json/schema/NumberSchema.java
+++ b/core/src/main/java/org/everit/json/schema/NumberSchema.java
@@ -16,6 +16,7 @@
 package org.everit.json.schema;

 import java.math.BigDecimal;
+import java.math.BigInteger;

 /**
  * Number schema validator.
@@ -183,7 +184,7 @@ public class NumberSchema extends Schema {
         throw new ValidationException(this, Number.class, subject);
       }
     } else {
-      if (!(subject instanceof Integer) && requiresInteger) {
+      if (!(subject instanceof Integer || subject instanceof BigInteger || subject instanceof Long) && requiresInteger) {
         throw new ValidationException(this, Integer.class, subject);
       }
       double intSubject = ((Number) subject).doubleValue();

@erosb
Copy link
Contributor

erosb commented Apr 3, 2016

@coderextreme yes, I've just committed a similar bugfix in 0450062 :)
The BigInteger check doesn't make sense though, the JSON-Java library will parse such long numbers as strings, therefore the NumberSchema#validate() method will never receive any BigInteger parameters - it is something to be fixed in the JSON-Java libary.

Anyway, thanks for your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants