java - How to validate a specific json structure in Jackson? -
i need way validate specific formatted json can represent class (in case book class) strings using jackson. there way of doing using jsonschema? or have in different way
objectmapper mapper = new objectmapper(); jsonschema jsonschema = mapper.generatejsonschema(book.class);
edit
you need use third party library this.
i.e. https://github.com/fge/json-schema-validator
objectmapper objectmapper = new objectmapper(); // line generate json schema class jsonnode schemanode = objectmapper.generatejsonschema(stagedetail.class).getschemanode(); // make json jsonnode jsonnode jsontovalidate = jsonloader.fromstring(json_to_validate); // validate against schema processingreport validate = jsonschemafactory.bydefault().getjsonschema(schemanode).validate(jsontovalidate); // validate.messages contains error massages system.out.println("valid? " + validate.issuccess());
Comments
Post a Comment