Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.time.LocalDate with @Future javax.validation annotation #70

Open
abhijitkottur opened this issue May 31, 2018 · 2 comments
Open

java.time.LocalDate with @Future javax.validation annotation #70

abhijitkottur opened this issue May 31, 2018 · 2 comments

Comments

@abhijitkottur
Copy link

abhijitkottur commented May 31, 2018

The @Future annotation does't seem to have any effect on the json schema.

.
.
.
@Future
private LocalDate date;
.
.
.

The generate schema looks like

.
.
.
"date": {
	"type": "array",
	"items": {
		"type": "integer"
	}
},
.
.
.

Is there any other way to enforce date validation?

@mbknor
Copy link
Owner

mbknor commented May 31, 2018

There is currently no support for javax.validation.constraints.Future.

You have two choices:

Send PR with added support for it.

Use the @JsonSchemaInject-annotation to insert the schema-code you want.
https://github.com/mbknor/mbknor-jackson-jsonSchema#flexible

@kog
Copy link
Contributor

kog commented Jul 21, 2018

I actually considered writing this as part of my earlier javax.validation contributions, but I don't think it's actually possible for v4 schema. I'm not exactly an expert on JSON schema, so if I've missed something, or someone knows how to do this, please do chime in.

Neither JSON nor the json-schema-validation draft spec contain a first-class type for date/time, This means that you get to use either a numeric value (think epochal timestamp) or a string. The validation spec does contain defined formats for dates and times as strings, but that doesn't really help us because a @Future annotation concerns the value of the field.

Without first class support for date/time you can't really do something like "is X after <some date/time>" because you have no way to make the comparison. And even if you could somehow compare it, there's no concept of "now" to compare it to.

I did look at json-schema-org/json-schema-spec#99 as well as the related json-schema-org/json-schema-spec#116, but it looks like these are still open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants