deeplearning4j/deeplearning4j · error · RuntimeException

Error deserializing ComputationGraphConfiguration -…

Error message

Error deserializing ComputationGraphConfiguration - configuration may have a custom layer, vertex or preprocessor, in pre version 1.0.0-beta JSON format.
Models in legacy format with custom 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

What it means

ComputationGraphConfiguration.fromJson wraps Jackson deserialization failures that stem from custom layers/vertices/preprocessors serialized in the pre-1.0.0-beta JSON format. Since 1.0.0-beta5, DL4J dropped support for deserializing such legacy custom classes directly, so when the type id cannot be resolved it rethrows with a message instructing the user to round-trip the model through DL4J 1.0.0-beta to 1.0.0-beta4.

Solutions

  1. Load the model in DL4J 1.0.0-beta through 1.0.0-beta4 and re-save it, then load the re-saved JSON in the current version.
  2. Register the custom classes with NeuralNetConfiguration.registerLegacyCustomClassesForJSON(YourLayer.class) before calling fromJson, if compatible.
  3. Rewrite the custom layer as a built-in or current-format layer and regenerate the configuration JSON.

Example fix

// before
ComputationGraphConfiguration conf = ComputationGraphConfiguration.fromJson(legacyJson); // throws
// after
NeuralNetConfiguration.registerLegacyCustomClassesForJSON(MyLegacyLayer.class);
ComputationGraphConfiguration conf = ComputationGraphConfiguration.fromJson(legacyJson);
Defensive patterns

Strategy: try-catch

Validate before calling

if (json.contains("@class") && usesLegacyCustomLayers) { NeuralNetConfiguration.registerLegacyCustomClassesForJSON(CustomLayersHolder.class); }

Try / catch

try { return ComputationGraphConfiguration.fromJson(json); } catch (RuntimeException e) { if (e.getMessage() != null && e.getMessage().contains("legacy")) { // round-trip via DL4J 1.0.0-beta..beta4 or register legacy classes } throw e; }

Prevention

When it happens

Trigger: Calling ComputationGraphConfiguration.fromJson(json) on a JSON config written by a DL4J version older than 1.0.0-beta that contains a custom Layer/GraphVertex/PreProcessor type id unknown to the current mapper, causing InvalidTypeIdException with 'Could not resolve type id'.

Common situations: Loading an old .json model config (or checkpoint) containing user-defined layers after upgrading DL4J past 1.0.0-beta4; CI pipelines reading archived legacy models; sharing models between projects with different custom layer sets.

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 deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/ba6b045f0b0bc1f8. Report an issue: GitHub.

Appendix: source

Thrown at deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/conf/ComputationGraphConfiguration.java:240

     * @param json the neural net configuration from json
     * @return {@link ComputationGraphConfiguration}
     */
    public static ComputationGraphConfiguration fromJson(String json) {
        //As per MultiLayerConfiguration.fromJson()
        ComputationGraphConfiguration conf;
        try {
            conf = mapper.readValue(json, ComputationGraphConfiguration.class);
        } catch (InvalidTypeIdException e){
            if(e.getMessage().contains("@class")){
                try{
                    //JSON may be legacy (1.0.0-alpha or earlier), attempt to load it using old format
                    return JsonMappers.getLegacyMapper().readValue(json, ComputationGraphConfiguration.class);
                } catch (InvalidTypeIdException e2){
                    //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, ..."
                    //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
                    String msg = e2.getMessage();
                    if(msg != null && msg.contains("Could not resolve type id")) {
                        throw new RuntimeException("Error deserializing ComputationGraphConfiguration - configuration may have a custom " +
                                "layer, vertex or preprocessor, in pre version 1.0.0-beta JSON format.\nModels in legacy format with custom" +
                                " 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);
                    }
                    throw new RuntimeException(e2);
                } catch (IOException e2){
                    throw new RuntimeException(e2);
                }
            }
            throw new RuntimeException(e);
        } catch (Exception e) {
            //Check if this exception came from legacy deserializer...
            String msg = e.getMessage();
            if(msg != null && msg.contains("legacy")){
                throw new RuntimeException("Error deserializing ComputationGraphConfiguration - 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...)", e);
            }
            throw new RuntimeException(e);

View on GitHub (pinned to 4c22ac5fe4)