{"record":{"id":"73452561af851e31","repo":"alibaba/spring-cloud-alibaba","slug":"invalid-date-format","errorCode":null,"errorMessage":"Invalid date format","messagePattern":"Invalid date format","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/annotation/CustomDateDeserializer.java","lineNumber":44,"sourceCode":"import com.fasterxml.jackson.databind.JsonNode;\n\npublic class CustomDateDeserializer extends JsonDeserializer<Date> {\n\n\tprivate final SimpleDateFormat dateFormat = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");\n\n\tpublic CustomDateDeserializer() {\n\t\tsuper();\n\t}\n\n\t@Override\n\tpublic Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {\n\t\tJsonNode node = jsonParser.getCodec().readTree(jsonParser);\n\t\tString date = node.textValue();\n\t\ttry {\n\t\t\treturn dateFormat.parse(date);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new IOException(\"Invalid date format\");\n\t\t}\n\t}\n}\n","sourceCodeStart":26,"sourceCodeEnd":48,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/annotation/CustomDateDeserializer.java#L26-L48","documentation":"Thrown by CustomDateDeserializer.deserialize, a Jackson JsonDeserializer<Date>. It reads a JSON node's text value and parses it with a fixed SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\"). Any value that does not match that exact pattern causes a ParseException, which is caught and rethrown as IOException(\"Invalid date format\"). The deserializer is intended for Nacos config payloads that carry timestamps in that strict format.","triggerScenarios":"A JSON config value bound through a Date field with this deserializer contains a date in a different format (ISO-8601 'yyyy-MM-dd', epoch millis, 'yyyy/MM/dd', 'yyyy-MM-ddTHH:mm:ss', etc.) or a non-date string. Jackson attempts to deserialize the field, parse fails, IOException bubbles up.","commonSituations":"Config authored as an ISO instant or date-only; upstream system emitting RFC-1123 or epoch numbers; copy-pasting a date in a localized format into Nacos config; version change where a field switched to this deserializer but the published config was not reformatted.","solutions":["Format the value in Nacos as exactly 'yyyy-MM-dd HH:mm:ss' (e.g., '2025-08-13 14:30:00').","If a different format is required, register a CustomDateDeserializer variant with the matching pattern, or use @JsonFormat(shape=STRING, pattern=...) on the field.","Strip timezone offsets / 'T' separators before publishing the config."],"exampleFix":"// before (config value)\n\"createTime\": \"2025-08-13T14:30:00Z\"\n// after\n\"createTime\": \"2025-08-13 14:30:00\"","handlingStrategy":"validation","validationCode":"// Validate the date string against the exact pattern before publishing/binding.\nprivate static final SimpleDateFormat FMT = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");\nFMT.setLenient(false);\ntry { FMT.parse(value); } catch (ParseException e) { /* reject */ }","typeGuard":"static boolean isValidNacosDate(String s) {\n    if (s == null) return false;\n    java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");\n    f.setLenient(false);\n    try { f.parse(s); return true; } catch (java.text.ParseException e) { return false; }\n}","tryCatchPattern":"try {\n    mapper.readValue(json, MyType.class);\n} catch (IOException e) {\n    if (\"Invalid date format\".equals(e.getMessage())) {\n        // reformat the offending config value to yyyy-MM-dd HH:mm:ss and retry\n    }\n}","preventionTips":["Author timestamps as 'yyyy-MM-dd HH:mm:ss'.","Avoid ISO 'T' separators and timezone offsets.","If you need another format, register a deserializer with the matching pattern."],"tags":["nacos","config","jackson","deserialization","date-format"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}