public LocalDate deserialize(JsonParser jsonparser, DeserializationContext context) throws IOException, JsonProcessingException { String date = jsonparser.getText(); LocalDate formattedDate; Pattern datePatt = Pattern.compile("^/Date\\((\\d+)([+-]\\d+)?\\)/$"); Matcher m = datePatt.matcher(date); if (m.matches()) { Long l = Long.parseLong(m.group(1)); formattedDate = Instant.ofEpochMilli(l).atZone(ZoneId.systemDefault()).toLocalDate(); } else { throw new IllegalArgumentException("Wrong date format"); } return formattedDate; } }
/** * Queries this date-time using the specified query. * <p> * This queries this date-time using the specified query strategy object. * The {@code TemporalQuery} object defines the logic to be used to * obtain the result. Read the documentation of the query to understand * what the result of this method will be. * <p> * The result of this method is obtained by invoking the * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the * specified query passing {@code this} as the argument. * * @param <R> the type of the result * @param query the query to invoke, not null * @return the query result, null may be returned (defined by the query) * @throws DateTimeException if unable to query (defined by the query) * @throws ArithmeticException if numeric overflow occurs (defined by the query) */ @SuppressWarnings("unchecked") @Override // override for Javadoc public <R> R query(TemporalQuery<R> query) { if (query == TemporalQueries.localDate()) { return (R) toLocalDate(); } return super.query(query); }
/** * Queries this date-time using the specified query. * <p> * This queries this date-time using the specified query strategy object. * The {@code TemporalQuery} object defines the logic to be used to * obtain the result. Read the documentation of the query to understand * what the result of this method will be. * <p> * The result of this method is obtained by invoking the * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the * specified query passing {@code this} as the argument. * * @param <R> the type of the result * @param query the query to invoke, not null * @return the query result, null may be returned (defined by the query) * @throws DateTimeException if unable to query (defined by the query) * @throws ArithmeticException if numeric overflow occurs (defined by the query) */ @SuppressWarnings("unchecked") @Override // override for Javadoc public <R> R query(TemporalQuery<R> query) { if (query == TemporalQueries.localDate()) { return (R) toLocalDate(); } return super.query(query); }