alibaba/arthas · error · IllegalStateException

Conversion from JSON to {type} failed

Error message

Conversion from JSON to {type} failed

What it means

JsonParser.fromJson(String, Class<T>) first tries fastjson's JSON.parseObject, and on failure falls back to Jackson's OBJECT_MAPPER.readValue. If Jackson also throws JsonProcessingException, both are discarded as cause and an IllegalStateException("Conversion from JSON to <type> failed") is raised. The wrapped cause is the fastjson exception, not the Jackson one.

Source

Thrown at arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/util/JsonParser.java:73

	private JsonParser() {
	}

	public static ObjectMapper getObjectMapper() {
		return OBJECT_MAPPER;
	}

	public static <T> T fromJson(String json, Class<T> type) {
		Assert.notNull(json, "json cannot be null");
		Assert.notNull(type, "type cannot be null");

		try {
			return JSON.parseObject(json, type);
		}
		catch (Exception ex) {
			try {
				return OBJECT_MAPPER.readValue(json, type);
			} catch (JsonProcessingException jacksonEx) {
				throw new IllegalStateException("Conversion from JSON to " + type.getName() + " failed", ex);
			}
		}
	}

	public static <T> T fromJson(String json, Type type) {
		Assert.notNull(json, "json cannot be null");
		Assert.notNull(type, "type cannot be null");

		try {
			return JSON.parseObject(json, type);
		}
		catch (Exception ex) {
			try {
				return OBJECT_MAPPER.readValue(json, OBJECT_MAPPER.constructType(type));
			} catch (JsonProcessingException jacksonEx) {
				throw new IllegalStateException("Conversion from JSON to " + type.getTypeName() + " failed", ex);
			}
		}

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Log and inspect the raw JSON payload at the call site to find the schema mismatch.
  2. Correct the target Class to match the actual JSON shape, or fix the producer to send the expected schema.
  3. If the payload may legitimately vary, deserialize into a permissive type (Map/Object) first then map manually.

Example fix

// before
Foo f = JsonParser.fromJson(json, Foo.class);

// after - diagnose then bind defensively
Object parsed = JsonParser.fromJson(json, Object.class);
logger.debug("payload={}", parsed);
Foo f = JsonParser.fromJson(json, Foo.class);
Defensive patterns

Strategy: try-catch

Validate before calling

if (json == null || json.isBlank()) {
    return defaultValue;
}
// optional: cheap pre-check that it's a JSON object/array

Try / catch

try {
    return JsonParser.fromJson(json, Target.class);
} catch (IllegalStateException e) {
    logger.error("Failed to bind JSON to {}: payload={}", Target.class, json, e);
    throw new MyApiException("Invalid payload shape", e);
}

Prevention

When it happens

Trigger: Passing malformed JSON, JSON whose structure cannot bind to the target Class (e.g. array into an object type, wrong field types), or null/non-text content to fromJson(json, SomeClass.class).

Common situations: Upstream MCP/tool returns an unexpected schema; wrong target Class supplied (e.g. Map vs POJO); numeric/string type mismatch in nested fields; truncated payload from a network read.

Related errors


AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14). Data as JSON: /api/errors/58ca232e5943e255. Report an issue: GitHub.