{"record":{"id":"97e70c396944e7fb","repo":"apache/seatunnel","slug":"object-to-json-exception","errorCode":null,"errorMessage":"Object to json exception!","messagePattern":"Object to json exception!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/JsonUtils.java","lineNumber":110,"sourceCode":"    }\n\n    public static JsonNode readTree(InputStream obj) throws IOException {\n        return OBJECT_MAPPER.readTree(obj);\n    }\n\n    /**\n     * json representation of object\n     *\n     * @param object object\n     * @param feature feature\n     * @return object to json string\n     */\n    public static String toJsonString(Object object, SerializationFeature feature) {\n        try {\n            ObjectWriter writer = OBJECT_MAPPER.writer(feature);\n            return writer.writeValueAsString(object);\n        } catch (Exception e) {\n            throw new RuntimeException(\"Object to json exception!\", e);\n        }\n    }\n\n    /**\n     * This method deserializes the specified Json into an object of the specified class. It is not\n     * suitable to use if the specified class is a generic type since it will not have the generic\n     * type information because of the Type Erasure feature of Java. Therefore, this method should\n     * not be used if the desired type is a generic type. Note that this method works fine if the\n     * any of the fields of the specified object are generics, just the object itself should not be\n     * a generic type.\n     *\n     * @param json the string from which the object is to be deserialized\n     * @param clazz the class of T\n     * @param <T> T\n     * @return an object of type T from the string classOfT\n     */\n    public static <T> T parseObject(String json, Class<T> clazz) {\n        if (StringUtils.isEmpty(json)) {","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/JsonUtils.java#L92-L128","documentation":"JsonUtils.toJsonString(Object, SerializationFeature) serializes an object to JSON with an extra Jackson SerializationFeature. Any failure during serialization (unwritable getters, infinite recursion, invalid state) is wrapped in this RuntimeException with the cause chained.","triggerScenarios":"Calling JsonUtils.toJsonString(obj, feature) when Jackson cannot serialize obj: self-referencing object graph (infinite recursion), getter throwing an exception, or an unsupported type with no serializer.","commonSituations":"Logging complex engine objects to JSON for debugging, serializing records with cyclic references (parent/child), passing objects with throwing getters (lazy fields already closed), upgrading Jackson and losing a custom serializer.","solutions":["Inspect the chained cause (getCause) for the real Jackson error, e.g. JsonMappingException 'Infinite recursion (StackOverflowError)'","Break cycles with @JsonIgnore or Jackson annotations on the offending fields","Ensure getters do not throw (close resources before serialization or expose copies)","Register a module/serializer for custom types, or convert to a plain DTO before serializing"],"exampleFix":"// before\nclass Node { Node parent; /* cyclic */ }\nJsonUtils.toJsonString(node, SerializationFeature.INDENT_OUTPUT);\n// after\nclass Node { @JsonIgnore Node parent; }\nJsonUtils.toJsonString(node, SerializationFeature.INDENT_OUTPUT);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    String json = JsonUtils.toJsonString(obj, feature);\n} catch (RuntimeException e) {\n    log.error(\"serialize failed for {}: {}\", obj.getClass().getName(), e.getCause(), e);\n    // fall back to toString() or a safe DTO\n}","preventionTips":["Break object cycles with @JsonIgnore/@JsonBackReference before serializing","Never serialize objects holding live resources (connections, streams)","Test serialization of all DTOs used for logging/persistence"],"tags":["jackson","serialization","runtime-exception"],"backgroundTag":"json-marshal-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}