I have two fields: startDate and endDate and I need to make sure the end date is equal to or later than the start date. What's the best way to do this?
I would like to ensure that endDate is deserialized after startDate so I can put the logic in its setter method like:
@JsonSetter( "end" )
public void setEnd(String end)
{
this.endDate = parseZonedDateTime( end );
//invalid
if ( this.endDate.compareTo( this.startDate ) < 0 )
{
//Throw a validation exception
}
}
But that only works if start is guaranteed to be set first.