{"record":{"id":"d15dc860d12f8395","repo":"baomidou/mybatis-plus","slug":"failed-to-deserialize-object-type","errorCode":null,"errorMessage":"Failed to deserialize object type","messagePattern":"Failed to deserialize object type","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/SerializationUtils.java","lineNumber":84,"sourceCode":"        return baos.toByteArray();\n    }\n\n    /**\n     * Deserialize the byte array into an object.\n     *\n     * @param bytes a serialized object\n     * @return the result of deserializing the bytes\n     */\n    public static Object deserialize(byte[] bytes) {\n        if (bytes == null) {\n            return null;\n        }\n        try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {\n            return ois.readObject();\n        } catch (IOException ex) {\n            throw new IllegalArgumentException(\"Failed to deserialize object\", ex);\n        } catch (ClassNotFoundException ex) {\n            throw new IllegalStateException(\"Failed to deserialize object type\", ex);\n        }\n    }\n}\n","sourceCodeStart":66,"sourceCodeEnd":88,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/SerializationUtils.java#L66-L88","documentation":"The ClassNotFoundException branch of SerializationUtils.deserialize: the byte stream names a class that is not on the current classpath, rethrown as IllegalStateException('Failed to deserialize object type'). The data is intact but the code needed to materialize it is missing or moved.","triggerScenarios":"Deserializing bytes written when class X existed, in a JVM/process where X (or its package after a rename/refactor/shade) is absent. Also cross-application cache sharing where one app writes entities the reader does not have; mybatis-plus serialized cache read after an entity class was renamed or its package restructured.","commonSituations":"Refactoring/renaming entity classes while old serialized cache/blob entries persist; rolling deployments where new nodes lack a class old nodes wrote; shaded jars changing package names; shared distributed caches between differently-built services.","solutions":["Restore or re-add the missing class (the exception's cause names the exact class).","Keep serialized class names stable: avoid renaming/moving entity classes that appear in serialized blobs, or migrate the data.","Clear/flush serialized caches after refactors so stale entries are regenerated.","For cross-service caches, serialize a neutral format (JSON/protobuf) instead of Java serialization."],"exampleFix":"// before: entity moved from com.acme.old.User to com.acme.user.User; old blobs unreadable\n// after: keep a compatibility alias or migrate data\npackage com.acme.old;\n@Deprecated\npublic class User extends com.acme.user.User implements java.io.Serializable {\n    private static final long serialVersionUID = <same as before>;\n}","handlingStrategy":"fallback","validationCode":"try {\n    Class.forName(classNameFromStreamHeaderIfKnown, true, getClass().getClassLoader());\n} catch (ClassNotFoundException e) {\n    // data references a class missing here: migrate or evict before deserialize\n}","typeGuard":null,"tryCatchPattern":"try {\n    return SerializationUtils.deserialize(bytes);\n} catch (IllegalStateException e) { // ClassNotFoundException branch\n    log.warn(\"serialized class missing on this node; evicting entry\", e);\n    cache.remove(key);\n    return recompute(key);\n}","preventionTips":["Avoid renaming/moving classes that appear in serialized blobs; keep serialVersionUID stable.","Flush serialized caches as part of refactor releases.","Prefer schema-stable formats (JSON) for cross-service persistence."],"tags":["serialization","classpath","refactoring","cache"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}