{"record":{"id":"78640b484be43878","repo":"testcontainers/testcontainers-java","slug":"can-t-serialize-arguments-args","errorCode":null,"errorMessage":"Can't serialize arguments: ${args}","messagePattern":"Can't serialize arguments: (.+?)","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/images/builder/dockerfile/statement/MultiArgsStatement.java","lineNumber":24,"sourceCode":"import java.util.Arrays;\n\npublic class MultiArgsStatement extends Statement {\n\n    private static final ObjectMapper objectMapper = new ObjectMapper();\n\n    protected final String[] args;\n\n    public MultiArgsStatement(String type, String... args) {\n        super(type);\n        this.args = args;\n    }\n\n    @Override\n    public void appendArguments(StringBuilder dockerfileStringBuilder) {\n        try {\n            dockerfileStringBuilder.append(objectMapper.writeValueAsString(args));\n        } catch (JsonProcessingException e) {\n            throw new RuntimeException(\"Can't serialize arguments: \" + Arrays.toString(args), e);\n        }\n    }\n}\n","sourceCodeStart":6,"sourceCodeEnd":28,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/images/builder/dockerfile/statement/MultiArgsStatement.java#L6-L28","documentation":"MultiArgsStatement.appendArguments serializes the statement's args array to JSON with Jackson and appends it to the Dockerfile. If Jackson cannot serialize the args, it throws a RuntimeException naming the args. This happens when an argument is of a type Jackson has no serializer for.","triggerScenarios":"Using a MultiArgsStatement-derived Dockerfile instruction (e.g. CMD, ENTRYPOINT, COPY with args) with elements that are not Strings/simple values — custom objects, unregistered date/time types, or types without Jackson serializers.","commonSituations":"Building a Dockerfile programmatically and passing runtime objects (URI, Path, nested POJOs) as command args; changing arg types after refactoring; Jackson version upgrades removing implicit serializers.","solutions":["Convert all args to Strings before constructing the statement (String.valueOf or explicit formatting).","Check the args array printed in the message for the non-serializable element.","If a complex type is intentional, ensure it's plain-data (records/POJOs with getters) or register the needed Jackson module."],"exampleFix":"// before\nnew MultiArgsStatement(\"CMD\", new Object[]{ Path.of(\"/app/run.sh\") });\n// after\nnew MultiArgsStatement(\"CMD\", new Object[]{ \"/app/run.sh\" });","handlingStrategy":"validation","validationCode":"for (Object arg : args) {\n    if (arg != null && !(arg instanceof String || arg instanceof Number || arg instanceof Boolean)) {\n        throw new IllegalArgumentException(\"CMD/ENTRYPOINT arg must be a simple value: \" + arg);\n    }\n}","typeGuard":"static boolean isSimpleArg(Object a) {\n    return a instanceof String || a instanceof Number || a instanceof Boolean;\n}","tryCatchPattern":"try {\n    statement.appendArguments(sb);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Can't serialize arguments\")) {\n        log.error(\"MultiArgsStatement args not JSON-serializable\", e);\n    }\n    throw e;\n}","preventionTips":["Pass String arrays to CMD/ENTRYPOINT statements","Convert Path/URI objects with toString() before use","Add a unit test that serializes the args map/array with Jackson"],"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"}