I try to check user detail object with use JSON schema. But I don't know how to check JSON object in Java.
My Schema:
{
"type" : "object",
"properties" : {
"first_name" : {
"type" : "string" ,
"minLength" : 3 ,
"maxLength" : 255
},
"last_name" : {
"type" : "string" ,
"minLength" : 3 ,
"maxLength" : 255
},
"age" : {
"type" : "integer" ,
"minimum" : 16 ,
"maximum" : 40
},
"phone_number" : {
"type" : "integer",
"pattern" : "[6-9][0-9]{9}"
} ,
"email" : {
"type" : "string",
"pattern" : "[a-z0-9]+"
} ,
"password" : {
"type" : "string" ,
"minLength" : 7 ,
"maxLength" : 255 ,
"pattern" : "^.{7, 255}$"
} ,
"gender" : { "enum" : ["Male" , "Female"] }
},
"required" : ["first_name","last_name" , "age" ,"email" , "password"
, "gender" ]
}
My Sample Input:
{
"first_name" : "Sample" ,
"last_name" : "Name" ,
"age" : 19,
"gender" : "Male",
"phone_number" : 9080245591,
"email" : "[email protected]",
"password" : "uni=versity"
}
Any one can say how to check this input with use JSON schema in Java.
The json-schema-validator in GitHub, Perhaps It will help you to check the json object in java.
You can use FasterXML jackson with the module:json-schema-validator as holten proposed.
Include it in maven: com.github.java-json-tools json-schema-validator 2.2.8
Complementary to this, to generate schema from object instead of writing it manually you can also use another module: https://github.com/FasterXML/jackson-module-jsonSchema
I may add a functional example if needed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With