简体   繁体   English

JsonSchema2Pojo,出生日期是用类型号生成的,我试图以整数形式传递值

[英]JsonSchema2Pojo, Date of Birth is generating with Type Number, I am trying to pass the value in Integer

I am currently Generating Pojo class using JsonSchema2Pojo, My json schema has couple of class related to Date of birth, Start Date and End date which is defined with type number, when i generate the Pojo class, its of type Double and I am unable to pass int value,我目前正在使用 JsonSchema2Pojo 生成 Pojo 类,我的 json 模式有几个与出生日期、开始日期和结束日期相关的类,这些类用类型号定义,当我生成 Pojo 类时,它的类型为 Double,我无法传递int值,

Eg if I am trying to set date of birth as 1/1/2020, it says Required Double and Passed int.例如,如果我尝试将出生日期设置为 1/1/2020,它会显示“Required Double”和“Passed int”。

I have tried to use true which has not worked, also I don't find any supporting tags to convert number to int in jsonschema2pojo properties我尝试使用 true ,但没​​有用,我也没有找到任何支持标签将 jsonschema2pojo 属性中的数字转换为 int

在此处输入图片说明

It looks like you need to manually change the type of those variables.看起来您需要手动更改这些变量的类型。

In general there is a bit discrepancy in the types between Java and Javascript.一般而言,Java 和 Javascript 之间的类型存在一些差异。 Javascript has only "number" for both int and float values. Javascript 对于 int 和 float 值只有“数字”。 Where Java has separate types. Java 有单独的类型。

I believe the generator uses Double since it is technically more correct but in you context you should go ahead and change the types to int or Integer manually.我相信生成器使用 Double,因为它在技术上更正确,但在您的上下文中,您应该继续手动将类型更改为 int 或 Integer。

If you can edit these field types to "integer" instead of "number" in your schema and use JsonSchema2Pojo then it will generate them as integer.如果您可以在架构中将这些字段类型编辑为“整数”而不是“数字”并使用 JsonSchema2Pojo,那么它会将它们生成为整数。

Alternatively, you could edit them manually if you don't want to change schema.或者,如果您不想更改架构,您可以手动编辑它们。

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

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