简体   繁体   English

具有类型转换功能的JSON模式验证

[英]JSON Schema Validation With typecasting feature

Please suggest how to perform typecasting before validation of JSON Schema in Java. 在Java中验证JSON模式之前,请提出如何执行类型转换。 I've achieved the same in NodeJS using json-schema-validation-pipeline package. 我已经使用json-schema-validation-pipeline包在NodeJS中实现了相同的目的。 Below code snippet for reference (where param1 was actually of type string as provided from backend API). 以下代码段供参考(其中param1实际上是后端API提供的字符串类型)。

var ValidationPipeline = require('json-schema-validation-pipeline');
var V = ValidationPipeline.V;
    var validate = ValidationPipeline([
        {
            $schema: {
                'param1': V(Number).min(60)
            }
        },
        { $cast: { param1: Number } }
    ]);

So basically, I am looking for equivalent solution in Java for above code snippet. 因此,基本上,我正在为上述代码段寻找Java的等效解决方案。 Thanks 谢谢

Assign it to POJO model class of JAVA and once you have this native object then you can typecast to anything as its in language operation For example- 将其分配给JAVA的POJO模型类,一旦有了该本地对象,便可以将其类型转换为语言操作中的任何内容,例如-

File file = new File("json/student.json");  

   // get json as buffer  
   BufferedReader br = new BufferedReader(new FileReader(file));  

   // obtained Gson object  
   Gson gson = new Gson();  //import com.google.gson.Gson;  

   // called fromJson() method and passed incoming buffer from json file  
   // passed student class reference to convert converted result as Student object  
   Student student = gson.fromJson(br, Student.class);  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM