{"record":{"id":"141426c388a70dfe","repo":"FasterXML/jackson-databind","slug":"failed-to-parse-date-value-s-s","errorCode":null,"errorMessage":"Failed to parse Date value '%s': %s","messagePattern":"Failed to parse Date value '(.+?)': (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/DeserializationContext.java","lineNumber":1185,"sourceCode":"     */\n\n    /**\n     * Convenience method for parsing a Date from given String, using\n     * currently configured date format (accessed using\n     * {@link DeserializationConfig#getDateFormat()}).\n     *<p>\n     * Implementation will handle thread-safety issues related to\n     * date formats such that first time this method is called,\n     * date format is cloned, and cloned instance will be retained\n     * for use during this deserialization round.\n     */\n    public Date parseDate(String dateStr) throws IllegalArgumentException\n    {\n        try {\n            DateFormat df = _getDateFormat();\n            return df.parse(dateStr);\n        } catch (ParseException e) {\n            throw new IllegalArgumentException(\"Failed to parse Date value '%s': %s\".formatted(dateStr,\n                    ClassUtil.exceptionMessage(e)));\n        }\n    }\n\n    /**\n     * Convenience method for constructing Calendar instance set\n     * to specified time, to be modified and used by caller.\n     */\n    public Calendar constructCalendar(Date d) {\n        // 08-Jan-2008, tatu: not optimal, but should work for the most part; let's revise as needed.\n        Calendar c = Calendar.getInstance(getTimeZone());\n        c.setTime(d);\n        return c;\n    }\n\n    /*\n    /**********************************************************************\n    /* Extension points for more esoteric data coercion","sourceCodeStart":1167,"sourceCodeEnd":1203,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/DeserializationContext.java#L1167-L1203","documentation":"DeserializationContext.parseDate() tries to parse a string into a java.util.Date using the currently configured DateFormat (the mapper's date format or the default ISO-8601 format). When DateFormat.parse() throws a ParseException, Jackson rethrows it as an IllegalArgumentException with both the offending value and the underlying parse message. This is the core failure for date/calendar deserialization when the input doesn't match the expected pattern.","triggerScenarios":"Deserializing a date field whose string value doesn't match the configured date format (e.g. '2024/01/01' against an ISO format, or 'Jan 1st' against 'yyyy-MM-dd'); no custom date format set and the input is non-ISO; locale/timezone mismatch causing the parser to reject a value; a numeric timestamp string where a formatted date was expected (or vice versa).","commonSituations":"Default Jackson expects ISO-8601 ('yyyy-MM-dd'T'HH:mm:ss.SSSX') but the API/DB returns 'MM/dd/yyyy'; timezone differences between server and client producing unparseable offsets; mixing java.util.Date with java.time types after a partial migration; CSV/legacy feeds with inconsistent date shapes; a JsonFormat annotation with a pattern that doesn't cover all incoming values.","solutions":["Set a matching date format on the mapper or field: mapper.setDateFormat(new SimpleDateFormat(\"MM/dd/yyyy\")) or @JsonFormat(shape=STRING, pattern=\"MM/dd/yyyy\").","Validate/sanitize incoming date strings upstream so only the expected pattern reaches Jackson.","Enable lenient parsing: ((SimpleDateFormat)fmt).setLenient(true) on the configured format.","Use a custom ValueDeserializer for Date that tries multiple patterns, or switch the field to java.time.LocalDate/Instant with ACCEPT_CASE_INSENSITIVE_VALUES / custom adapters.","Enable DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE and verify the input includes/excludes timezone as the pattern expects."],"exampleFix":"// before\nObjectMapper m = new ObjectMapper(); // default ISO format\nDate d = m.readValue(\"\\\"01/14/2024\\\"\", Date.class); // fails\n// after\nSimpleDateFormat f = new SimpleDateFormat(\"MM/dd/yyyy\");\nf.setTimeZone(TimeZone.getTimeZone(\"UTC\"));\nJsonMapper m = JsonMapper.builder().defaultDateFormat(f).build();\nDate d = m.readValue(\"\\\"01/14/2024\\\"\", Date.class);","handlingStrategy":"try-catch","validationCode":"// Pre-validate a date string against the configured format before parse\nstatic boolean isParsable(DateFormat fmt, String s) {\n    try { synchronized (fmt) { fmt.parse(s); } return true; }\n    catch (ParseException e) { return false; }\n}","typeGuard":"// No compile-time type guard for runtime string parsing; rely on validation.","tryCatchPattern":"try {\n    return mapper.readValue(json, Date.class);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Failed to parse Date value\")) {\n        // fall back: store raw string or use a default date\n    }\n    throw e;\n}","preventionTips":["Set an explicit, documented date format on the mapper or field via @JsonFormat.","Centralize date parsing in one place so the format is consistent across your app.","Use java.time (LocalDate/Instant) with dedicated deserializers instead of java.util.Date where possible.","Add integration tests using real production date samples."],"tags":["deserialization","date-parsing","configuration","data-format"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}