{"record":{"id":"0ff9f6f5eab13538","repo":"testcontainers/testcontainers-java","slug":"failed-to-convert-arguments-into-json-e-getmessage","errorCode":null,"errorMessage":"Failed to convert arguments into json: ${e.getMessage()}","messagePattern":"Failed to convert arguments into json: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/rabbitmq/src/main/java/org/testcontainers/containers/RabbitMQContainer.java","lineNumber":721,"sourceCode":"    }\n\n    /**\n     * Overwrites the default RabbitMQ configuration file with the supplied one.\n     *\n     * @param rabbitMQConf The rabbitmq.config file to use (in erlang format)\n     * @return This container.\n     */\n    public RabbitMQContainer withRabbitMQConfigErlang(MountableFile rabbitMQConf) {\n        withEnv(\"RABBITMQ_CONFIG_FILE\", \"/etc/rabbitmq/rabbitmq-custom.config\");\n        return withCopyFileToContainer(rabbitMQConf, \"/etc/rabbitmq/rabbitmq-custom.config\");\n    }\n\n    @NotNull\n    private String toJson(Map<String, Object> arguments) {\n        try {\n            return new ObjectMapper().writeValueAsString(arguments);\n        } catch (JsonProcessingException e) {\n            throw new RuntimeException(\"Failed to convert arguments into json: \" + e.getMessage(), e);\n        }\n    }\n}\n","sourceCodeStart":703,"sourceCodeEnd":725,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/rabbitmq/src/main/java/org/testcontainers/containers/RabbitMQContainer.java#L703-L725","documentation":"RabbitMQContainer.toJson serializes a Map of queue/exchange/binding/policy arguments to JSON with Jackson before sending them to the RabbitMQ HTTP management API. If Jackson cannot serialize the map (JsonProcessingException), it wraps it in a RuntimeException with this message. It almost always means one of the argument values is not JSON-serializable by the default ObjectMapper.","triggerScenarios":"Calling withQueue(), withExchange(), withBinding(), withPolicy(), or withOperatorPolicy() with an arguments map containing a value Jackson cannot write, e.g. an arbitrary non-POJO object, an unserializable type, or (rarely) a map with a null key.","commonSituations":"Passing custom typed option objects (e.g. x-message-ttl as a custom wrapper or BigDecimal with broken config), reusing a Map with mixed/generic Object values containing framework types (OutputStream, lambdas, Hibernate entities), or copy-pasting arguments built for another client library.","solutions":["Inspect the arguments map passed to withQueue/withExchange/withBinding/withPolicy/withOperatorPolicy and remove or replace values that are not plain JSON types (String, Number, Boolean, List, Map).","Ensure numeric arguments are standard types like Integer/Long, not exotic Number subclasses or wrapper objects.","Enable ObjectMapper FAIL_ON_EMPTY_BEANS awareness: if a value is a complex bean, convert it yourself to a Map/List before passing it.","Wrap the call in try/catch RuntimeException and log the arguments map to identify the offending entry.","If a value must be a custom object, serialize it first (new ObjectMapper().writeValueAsString(value)) and pass the resulting JSON-friendly structure."],"exampleFix":"// before\nMap<String, Object> args = new HashMap<>();\nargs.put(\"x-message-ttl\", Duration.ofSeconds(30)); // not a plain number\ncontainer.withQueue(\"q\", args);\n// after\nMap<String, Object> args = new HashMap<>();\nargs.put(\"x-message-ttl\", 30_000); // Integer/Long serializes fine\ncontainer.withQueue(\"q\", args);","handlingStrategy":"validation","validationCode":"static boolean isJsonSerializable(Object v) {\n  try { new ObjectMapper().writeValueAsString(v); return true; }\n  catch (JsonProcessingException e) { return false; }\n}\n// assert args.values().stream().allMatch(MyContainer::isJsonSerializable);","typeGuard":"static boolean isPlainJsonType(Object v) {\n  return v == null || v instanceof String || v instanceof Number || v instanceof Boolean\n      || v instanceof Map || v instanceof List;\n}","tryCatchPattern":"try {\n  container.withQueue(\"q\", args);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Failed to convert arguments into json\")) {\n    throw new IllegalStateException(\"Non-JSON-serializable argument in map: \" + args, e);\n  }\n  throw e;\n}","preventionTips":["Restrict argument maps to String/Number/Boolean/List/Map values","Convert custom option objects to Maps before passing","Keep numeric options as Integer/Long, not exotic Number types","Unit-test any helper that builds RabbitMQ argument maps"],"tags":["jackson","json-serialization","rabbitmq","arguments"],"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"}