alibaba/spring-cloud-alibaba · error · IOException

Invalid date format

Error message

Invalid date format

What it means

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.

Solutions

  1. Format the value in Nacos as exactly 'yyyy-MM-dd HH:mm:ss' (e.g., '2025-08-13 14:30:00').
  2. If a different format is required, register a CustomDateDeserializer variant with the matching pattern, or use @JsonFormat(shape=STRING, pattern=...) on the field.
  3. Strip timezone offsets / 'T' separators before publishing the config.

Example fix

// before (config value)
"createTime": "2025-08-13T14:30:00Z"
// after
"createTime": "2025-08-13 14:30:00"
Defensive patterns

Strategy: validation

Validate before calling

// Validate the date string against the exact pattern before publishing/binding.
private static final SimpleDateFormat FMT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
FMT.setLenient(false);
try { FMT.parse(value); } catch (ParseException e) { /* reject */ }

Type guard

static boolean isValidNacosDate(String s) {
    if (s == null) return false;
    java.text.SimpleDateFormat f = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    f.setLenient(false);
    try { f.parse(s); return true; } catch (java.text.ParseException e) { return false; }
}

Try / catch

try {
    mapper.readValue(json, MyType.class);
} catch (IOException e) {
    if ("Invalid date format".equals(e.getMessage())) {
        // reformat the offending config value to yyyy-MM-dd HH:mm:ss and retry
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/73452561af851e31. Report an issue: GitHub.

Appendix: source

Thrown at spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/annotation/CustomDateDeserializer.java:44

import com.fasterxml.jackson.databind.JsonNode;

public class CustomDateDeserializer extends JsonDeserializer<Date> {

	private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	public CustomDateDeserializer() {
		super();
	}

	@Override
	public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
		JsonNode node = jsonParser.getCodec().readTree(jsonParser);
		String date = node.textValue();
		try {
			return dateFormat.parse(date);
		}
		catch (Exception e) {
			throw new IOException("Invalid date format");
		}
	}
}

View on GitHub (pinned to 115d590110)