apache/seatunnel · error · RuntimeException

Json parse object exception!

Error message

Json parse object exception!

What it means

JsonUtils.parseObject(String, Class<T>) deserializes a JSON string into an instance of the given class. If Jackson cannot parse the JSON or bind it to the target type, it rethrows as this RuntimeException with the original exception as cause.

Source

Thrown at seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/JsonUtils.java:135

     * type information because of the Type Erasure feature of Java. Therefore, this method should
     * not be used if the desired type is a generic type. Note that this method works fine if the
     * any of the fields of the specified object are generics, just the object itself should not be
     * a generic type.
     *
     * @param json the string from which the object is to be deserialized
     * @param clazz the class of T
     * @param <T> T
     * @return an object of type T from the string classOfT
     */
    public static <T> T parseObject(String json, Class<T> clazz) {
        if (StringUtils.isEmpty(json)) {
            return null;
        }

        try {
            return OBJECT_MAPPER.readValue(json, clazz);
        } catch (Exception e) {
            throw new RuntimeException("Json parse object exception!", e);
        }
    }

    /**
     * json to list
     *
     * @param json json string
     * @param clazz class
     * @param <T> T
     * @return list
     */
    public static <T> List<T> toList(String json, Class<T> clazz) {
        if (StringUtils.isEmpty(json)) {
            return Collections.emptyList();
        }

        try {
            CollectionType listType =

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Check the chained cause: JsonParseException means the input is not valid JSON; MismatchedInputException means shape/type mismatch
  2. Validate/trim the input string; ensure it is non-empty and starts with '{' for object targets
  3. If the payload is an array, use JsonUtils.toList or parseArray instead
  4. Add missing @JsonIgnoreProperties(ignoreUnknown = true) or fix field types in the target class

Example fix

// before
MyDto dto = JsonUtils.parseObject(arrayJsonText, MyDto.class); // input is a JSON array
// after
List<MyDto> list = JsonUtils.toList(arrayJsonText, MyDto.class);
Defensive patterns

Strategy: try-catch

Validate before calling

boolean isJsonObject(String s) { return s != null && s.trim().startsWith("{"); }

Try / catch

try {
    MyDto dto = JsonUtils.parseObject(json, MyDto.class);
} catch (RuntimeException e) {
    log.error("bad json payload: {}", json, e.getCause());
    throw new IllegalArgumentException("invalid json for MyDto", e);
}

Prevention

When it happens

Trigger: Calling JsonUtils.parseObject(json, clazz) with malformed JSON, a valid JSON scalar/array when an object is expected, or fields that do not match the target class's types (e.g. a string where an int is required).

Common situations: Parsing responses from external services that return HTML error pages instead of JSON, empty or truncated strings, passing a JSON array into parseObject for a bean, schema drift after upgrading the target class.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/d27222736a053e50. Report an issue: GitHub.