@@ -92,4 +92,51 @@ void testTypeLoose() {
92
92
assertEquals (1 , messages .size ());
93
93
94
94
}
95
+
96
+ /**
97
+ * Issue 864.
98
+ */
99
+ @ Test
100
+ void integer () {
101
+ String schemaData = "{\r \n "
102
+ + " \" type\" : \" integer\" \r \n "
103
+ + "}" ;
104
+ JsonSchema schema = JsonSchemaFactory .getInstance (VersionFlag .V202012 ).getSchema (schemaData );
105
+ Set <ValidationMessage > messages = schema .validate ("1" , InputFormat .JSON );
106
+ assertEquals (0 , messages .size ());
107
+ messages = schema .validate ("2.0" , InputFormat .JSON );
108
+ assertEquals (0 , messages .size ());
109
+ messages = schema .validate ("2.000001" , InputFormat .JSON );
110
+ assertEquals (1 , messages .size ());
111
+ }
112
+
113
+ /**
114
+ * Issue 864.
115
+ * <p>
116
+ * In draft-04, "integer" is listed as a primitive type and defined as "a JSON
117
+ * number without a fraction or exponent part"; in draft-06, "integer" is not
118
+ * considered a primitive type and is only defined in the section for keyword
119
+ * "type" as "any number with a zero fractional part"; 1.0 is thus not a valid
120
+ * "integer" type in draft-04 and earlier, but is a valid "integer" type in
121
+ * draft-06 and later; note that both drafts say that integers SHOULD be encoded
122
+ * in JSON without fractional parts
123
+ *
124
+ * @see <a href=
125
+ * "https://json-schema.org/draft-06/json-schema-release-notes">Draft-06
126
+ * Release Notes</a>
127
+ */
128
+ @ Test
129
+ void integerDraft4 () {
130
+ String schemaData = "{\r \n "
131
+ + " \" type\" : \" integer\" \r \n "
132
+ + "}" ;
133
+ JsonSchema schema = JsonSchemaFactory .getInstance (VersionFlag .V4 ).getSchema (schemaData );
134
+ Set <ValidationMessage > messages = schema .validate ("1" , InputFormat .JSON );
135
+ assertEquals (0 , messages .size ());
136
+ // The logic in JsonNodeUtil specifically excludes V4 from this handling
137
+ messages = schema .validate ("2.0" , InputFormat .JSON );
138
+ assertEquals (1 , messages .size ());
139
+ messages = schema .validate ("2.000001" , InputFormat .JSON );
140
+ assertEquals (1 , messages .size ());
141
+ }
95
142
}
0 commit comments