{"record":{"id":"cbaac13a90ae42dd","repo":"testcontainers/testcontainers-java","slug":"can-t-serialize-entry-entry","errorCode":null,"errorMessage":"Can't serialize entry: ${entry}","messagePattern":"Can't serialize entry: (.+?)","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/images/builder/dockerfile/statement/KeyValuesStatement.java","lineNumber":35,"sourceCode":"        super(type);\n        this.entries = entries;\n    }\n\n    @Override\n    public void appendArguments(StringBuilder dockerfileStringBuilder) {\n        Set<Map.Entry<String, String>> entries = this.entries.entrySet();\n\n        Iterator<Map.Entry<String, String>> iterator = entries.iterator();\n\n        while (iterator.hasNext()) {\n            Map.Entry<String, String> entry = iterator.next();\n\n            try {\n                dockerfileStringBuilder.append(objectMapper.writeValueAsString(entry.getKey()));\n                dockerfileStringBuilder.append(\"=\");\n                dockerfileStringBuilder.append(objectMapper.writeValueAsString(entry.getValue()));\n            } catch (JsonProcessingException e) {\n                throw new RuntimeException(\"Can't serialize entry: \" + entry, e);\n            }\n\n            if (iterator.hasNext()) {\n                dockerfileStringBuilder.append(\" \\\\\\n\\t\");\n            }\n        }\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":44,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/images/builder/dockerfile/statement/KeyValuesStatement.java#L17-L44","documentation":"KeyValuesStatement.appendArguments serializes each Map.Entry key/value to JSON via Jackson to build a Dockerfile instruction (e.g. ENV/LABEL). If Jackson cannot serialize the key or value, it wraps the JsonProcessingException in a RuntimeException naming the offending entry. This usually means a key/value is not JSON-serializable (e.g. an arbitrary POJO without Jackson support, or an ObjectMapper customization issue).","triggerScenarios":"Calling ImageFromDockerfile (or a DockerfileBuilder ENV/LABEL-style statement) with a Map containing keys or values that Jackson cannot write, e.g. non-trivial objects, nulls in unsupported spots, or exotic types with no serializer.","commonSituations":"Passing parsed config objects (Map<String, Object> with nested POJOs or Date/Duration types without JavaTimeModule) instead of simple strings into a key-values statement; upgrading Jackson and losing a module; custom types lacking getters.","solutions":["Inspect the failing entry printed in the message and replace the offending key/value with a plain String (e.g. String.valueOf(value)).","If you need object serialization, register the required Jackson module (e.g. JavaTimeModule) — configure via the statement's ObjectMapper if exposed.","Avoid nested/complex objects: flatten your map to Map<String, String> before building the statement."],"exampleFix":"// before\nMap<String, Object> env = new HashMap<>();\nenv.put(\"CONFIG\", myConfigPojo);\nnew KeyValuesStatement(\"ENV\", env);\n// after\nMap<String, String> env = new HashMap<>();\nenv.put(\"CONFIG\", String.valueOf(myConfigPojo));\nnew KeyValuesStatement(\"ENV\", env);","handlingStrategy":"validation","validationCode":"for (Map.Entry<?,?> e : env.entrySet()) {\n    if (!(e.getValue() instanceof String || e.getValue() instanceof Number || e.getValue() instanceof Boolean)) {\n        throw new IllegalArgumentException(\"Non-serializable ENV value for key: \" + e.getKey());\n    }\n}","typeGuard":"static boolean isJsonSerializable(Object v) {\n    return v == null || v instanceof String || v instanceof Number || v instanceof Boolean || v instanceof Map || v instanceof List;\n}","tryCatchPattern":"try {\n    statement.appendArguments(sb);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Can't serialize\")) {\n        log.error(\"Dockerfile entry not JSON-serializable; flatten map to strings\", e);\n    }\n    throw e;\n}","preventionTips":["Build key-value maps as Map<String, String> for Dockerfile statements","Avoid passing POJOs or java.time types into ENV/LABEL values","Test Dockerfile-building code paths in unit tests"],"tags":["jackson","serialization","dockerfile"],"backgroundTag":"json-serialization-failed","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}