/** * Obtains an instance of {@code LocalDate} from a text string such as {@code 2007-12-23}. * <p> * The string must represent a valid date and is parsed using * {@link org.threeten.bp.format.DateTimeFormatter#ISO_LOCAL_DATE}. * * @param text the text to parse such as "2007-12-23", not null * @return the parsed local date, not null * @throws DateTimeParseException if the text cannot be parsed */ public static LocalDate parse(CharSequence text) { return parse(text, DateTimeFormatter.ISO_LOCAL_DATE); }
/** * Obtains an instance of {@code LocalDate} from a text string such as {@code 2007-12-03}. * <p> * The string must represent a valid date and is parsed using * {@link org.threeten.bp.format.DateTimeFormatter#ISO_LOCAL_DATE}. * * @param text the text to parse such as "2007-12-03", not null * @return the parsed local date, not null * @throws DateTimeParseException if the text cannot be parsed */ public static LocalDate parse(CharSequence text) { return parse(text, DateTimeFormatter.ISO_LOCAL_DATE); }
@Nullable public static LocalDate dbStringToLocalDate(@Nullable String text) { if (text != null && text.length() > 0 && !text.equals("null")) { try { return LocalDate.parse(text, DB_DATE_FORMATTER310); } catch (Exception ex) { throw new IllegalArgumentException("Cannot parse date text: " + text, ex); } } else { return null; } }
@Override public LocalDate read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); return LocalDate.parse(date, formatter); } } }
@Override public LocalDate read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); return LocalDate.parse(date, formatter); } } }
@Override public LocalDate read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); return LocalDate.parse(date, formatter); } } }
@Override protected LocalDate deserialize(String key, DeserializationContext ctxt) throws IOException { try { return LocalDate.parse(key, DateTimeFormatter.ISO_LOCAL_DATE); } catch (DateTimeException e) { return _rethrowDateTimeException(ctxt, LocalDate.class, e, key); } } }
@Override public LocalDate read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); return LocalDate.parse(date, formatter); } } }
@Override public LocalDate read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); return LocalDate.parse(date, formatter); } } }
@Override public LocalDate read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); return LocalDate.parse(date, formatter); } } }
@Override public LocalDate read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); return LocalDate.parse(date, formatter); } } }
@Override public ScalarDate toValue(String value) { return new LocalDateScalarDate(LocalDate.parse(value)); }
@Override public LocalDate read(JsonReader in) throws IOException { switch (in.peek()) { case NULL: in.nextNull(); return null; default: String date = in.nextString(); return LocalDate.parse(date, formatter); } } }
@Override public ScalarDate fromJsonValue(JsonString value) { return new LocalDateScalarDate(LocalDate.parse(value.getString())); } }
public static GsonBuilder getGsonBuilder() { GsonBuilder builder = new GsonBuilder(); // trakt exclusively uses ISO 8601 date times with milliseconds and time zone offset // such as '2011-12-03T10:15:30.000+01:00' or '2011-12-03T10:15:30.000Z' builder.registerTypeAdapter(OffsetDateTime.class, (JsonDeserializer<OffsetDateTime>) (json, typeOfT, context) -> OffsetDateTime.parse(json.getAsString())); builder.registerTypeAdapter(OffsetDateTime.class, (JsonSerializer<OffsetDateTime>) (src, typeOfSrc, context) -> new JsonPrimitive(src.toString())); // dates are in ISO 8601 format as well builder.registerTypeAdapter(LocalDate.class, (JsonDeserializer<LocalDate>) (json, typeOfT, context) -> LocalDate.parse(json.getAsString())); // privacy builder.registerTypeAdapter(ListPrivacy.class, (JsonDeserializer<ListPrivacy>) (json, typeOfT, context) -> ListPrivacy.fromValue(json.getAsString())); // rating builder.registerTypeAdapter(Rating.class, (JsonDeserializer<Rating>) (json, typeOfT, context) -> Rating.fromValue(json.getAsInt())); builder.registerTypeAdapter(Rating.class, (JsonSerializer<Rating>) (src, typeOfSrc, context) -> new JsonPrimitive(src.value)); // sort by builder.registerTypeAdapter(SortBy.class, (JsonDeserializer<SortBy>) (json, typeOfT, context) -> SortBy.fromValue(json.getAsString())); // sort how builder.registerTypeAdapter(SortHow.class, (JsonDeserializer<SortHow>) (json, typeOfT, context) -> SortHow.fromValue(json.getAsString())); // status builder.registerTypeAdapter(Status.class, (JsonDeserializer<Status>) (json, typeOfT, context) -> Status.fromValue(json.getAsString())); return builder; }