{"record":{"id":"a37c2ac0aed12eec","repo":"deeplearning4j/deeplearning4j","slug":"error-deserializing-multilayerconfiguration-conf-a37c2a","errorCode":null,"errorMessage":"Error deserializing MultiLayerConfiguration - configuration may have a custom layer, vertex or preprocessor, in pre version 1.0.0-alpha JSON format. These layers can be deserialized by first registering them with NeuralNetConfiguration.registerLegacyCustomClassesForJSON(Class...)","messagePattern":"Error deserializing MultiLayerConfiguration - configuration may have a custom layer, vertex or preprocessor, in pre version 1\\.0\\.0-alpha JSON format\\. These layers can be deserialized by first registering them with NeuralNetConfiguration\\.registerLegacyCustomClassesForJSON\\(Class\\.\\.\\.\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/conf/MultiLayerConfiguration.java","lineNumber":244,"sourceCode":"                    //Check for legacy custom layers: \"Could not resolve type id 'CustomLayer' as a subtype of [simple type, class org.deeplearning4j.nn.conf.layers.Layer]: known type ids = [Bidirectional, CenterLossOutputLayer, CnnLossLayer, ...\"\n                    //1.0.0-beta5: dropping support for custom layers defined in pre-1.0.0-beta format. Built-in layers from these formats still work\n                    String msg = e2.getMessage();\n                    if(msg != null && msg.contains(\"Could not resolve type id\")){\n                        throw new RuntimeException(\"Error deserializing MultiLayerConfiguration - configuration may have a custom \" +\n                                \"layer, vertex or preprocessor, in pre version 1.0.0-beta JSON format.\\nModels in legacy format with custom\" +\n                                \" layers should be loaded in 1.0.0-beta to 1.0.0-beta4 and saved again, before loading in the current version of DL4J\", e);\n                    }\n                    throw new RuntimeException(e2);\n                } catch (IOException e2) {\n                    throw new RuntimeException(e2);\n                }\n            }\n            throw new RuntimeException(e);\n        } catch (IOException e) {\n            //Check if this exception came from legacy deserializer...\n            String msg = e.getMessage();\n            if (msg != null && msg.contains(\"legacy\")) {\n                throw new RuntimeException(\"Error deserializing MultiLayerConfiguration - configuration may have a custom \" +\n                        \"layer, vertex or preprocessor, in pre version 1.0.0-alpha JSON format. These layers can be \" +\n                        \"deserialized by first registering them with NeuralNetConfiguration.registerLegacyCustomClassesForJSON(Class...)\", e);\n            }\n            throw new RuntimeException(e);\n        }\n\n\n        //To maintain backward compatibility after loss function refactoring (configs generated with v0.5.0 or earlier)\n        // Previously: enumeration used for loss functions. Now: use classes\n        // IN the past, could have only been an OutputLayer or RnnOutputLayer using these enums\n        int layerCount = 0;\n        JsonNode confs = null;\n        for (NeuralNetConfiguration nnc : conf.getConfs()) {\n            Layer l = nnc.getLayer();\n            if (l instanceof BaseOutputLayer && ((BaseOutputLayer) l).getLossFn() == null) {\n                //lossFn field null -> may be an old config format, with lossFunction field being for the enum\n                //if so, try walking the JSON graph to extract out the appropriate enum value\n","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/conf/MultiLayerConfiguration.java#L226-L262","documentation":"MultiLayerConfiguration.fromJson throws this RuntimeException when an IOException during deserialization indicates a legacy (pre-1.0.0-alpha) custom layer. Unlike the beta5 hard drop, these custom classes can still be resolved if the application first registers them via NeuralNetConfiguration.registerLegacyCustomClassesForJSON(Class...). The message tells you exactly which registration call is needed.","triggerScenarios":"Calling fromJson on configuration JSON containing custom layers serialized before 1.0.0-alpha, without having registered those custom classes for legacy JSON handling.","commonSituations":"Loading very old (2017-era) model files with custom layer subclasses; forgetting the registerLegacyCustomClassesForJSON call before deserialization; class moved/renamed so registration no longer matches.","solutions":["Call NeuralNetConfiguration.registerLegacyCustomClassesForJSON(YourCustomLayer.class) before fromJson","Ensure the custom class is on the classpath with the same name as in the JSON","If registration is not possible, re-create the layer config manually from the JSON content"],"exampleFix":"// before\nMultiLayerConfiguration conf = MultiLayerConfiguration.fromJson(json); // RuntimeException\n// after\nNeuralNetConfiguration.registerLegacyCustomClassesForJSON(MyCustomLayer.class);\nMultiLayerConfiguration conf = MultiLayerConfiguration.fromJson(json);","handlingStrategy":"try-catch","validationCode":"// before deserialization, ensure registration ran:\nif (!legacyClassesRegistered) NeuralNetConfiguration.registerLegacyCustomClassesForJSON(MyCustomLayer.class, MyOtherLayer.class);","typeGuard":null,"tryCatchPattern":"try { return MultiLayerConfiguration.fromJson(json); } catch (RuntimeException e) { if (e.getMessage().contains(\"registerLegacyCustomClassesForJSON\")) { NeuralNetConfiguration.registerLegacyCustomClassesForJSON(MyCustomLayer.class); return MultiLayerConfiguration.fromJson(json); } throw e; }","preventionTips":["Register legacy custom classes once at application startup, before any model loading","Keep custom layer classes at stable fully-qualified names matching old JSON","Convert pre-alpha models to current format as part of a one-time migration"],"tags":["deeplearning4j","json","deserialization","legacy","custom-layers"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"4c22ac5fe4a8350d05d224e7f4499429f7f69c93","analyzedAt":"2026-09-07T05:27:04.714Z","contentChangedAt":"2026-09-07T05:27:04.714Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}