Reputation: 1351
I am constructing a Json schema file which is read by my C# code on validating Json files. One of the property I used is something like this
"XOSCLockTime": {
"type": "double"
}
and it works fine, but in order to handle null values we are suppose to do something like this
"XOSCLockTime": {
"type": ["double", "null"]
}
and this gives error saying double is not an acceptable value here?? What is wrong here?? Does for data type double null values are handled automatically??
this is a snap shot of my schema file
"TestStationSerialNumber": {
"type": ["string", "null"]
},
"TestStationType": {
"type": ["string", "null"]
},
"X": {
"type": ["integer", "null"]
},
here i replaced double with integer after i start getting error. if i put double i get this error on schema file" Value is not accepted. Valid values: "array", "boolean", "integer", "null", "number", "object", "string"."
Upvotes: 3
Views: 14661
Reputation: 236
You could also use the below two properties which would give you the expected result.
minimum
and maximum
For example in our case we wanted to have longitude and latitude in double in Json schema so we had below schema definition:
"latitude": {
"type": [
"null",
"number"
],
"minimum": -90,
"maximum": 90
},
"longitude": {
"type": [
"null",
"number"
],
"minimum": -180,
"maximum": 180
}
and generated classed has below properties:
@Nullable
private Double latitude;
@Nullable
private Double longitude;
Upvotes: 0
Reputation: 72256
double
is not a type recognized by JSON schema. JSON schema defines the following data types: string
, number
, integer
, object
, array
, boolean
and null
.
There are two numeric types: integer
and number
.
If your numbers are not integral numbers then number
is the type you need.
Upvotes: 3