我刚刚开始使用jsonschema和一个例子 "在Java项目中使用jsonschema2pojo(嵌入式)" 在 https://github.com/joelittlejohn/jsonschema2pojo/wiki/Getting-Started
考虑到此处列出的jsonschema数据类型 https://developers.google.com/discovery/v1/type-format?hl=en
我的架构对象可以描述为
{
"$schema": "http://json-schema.org/draft-04/schema",
"description": "Document",
"type": "object",
"properties": {
"displayDate": { "type": "date" },
"displayName": { "type": "string" }
}
}
不幸的是,生成的Pojo对象将是
package com.example;
public interface Document {
java.lang.Object getDisplayDate();
void setDisplayDate(java.lang.Object arg0);
java.lang.String getDisplayName();
void setDisplayName(java.lang.String arg0);
}
有一个成员" displayDate"类型为Object而不是预期Date。为什么呢?
答案 0 :(得分:2)
date
不是type
的有效值。 displayDate
应定义为
{ "type": "string", "format": "date" }
我不知道jsonschema2pojo是否会将其转换为您想要的Date对象,但它似乎默认为Object而不是在遇到type
的无效值时抛出错误。
答案 1 :(得分:1)
根据最新的jsonschema2pojo文档,对于类型getX()
,您需要执行以下操作:-
Date
在生成的POJO中,属性的类型为{ "type": "string", "format": "date-time" }
对象