Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) on withCreateContainerCmdModifier and withNetwork
See original GitHub issueI was using GenericContainer below and encounter issue
Caused by: org.testcontainers.shaded.com.fasterxml.jackson.databind.JsonMappingException: Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) (through reference chain: org.testcontainers.shaded.com.github.dockerjava.core.command.CreateContainerCmdImpl["NetworkingConfig"]->org.testcontainers.shaded.com.github.dockerjava.core.command.CreateContainerCmdImpl$NetworkingConfig["EndpointsConfig"])
GenericContainer<?> xContainer = new GenericContainer<>("x:latest")
.withExposedPorts(8080)
.withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
new HostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(8080), new ExposedPort(8081)))
))
.withNetwork(network);
further investigation shows that the error exists only when withCreateContainerCmdModifier and withNetwork are used at the same time. If they are used without the other it works. But I need both of them one for mapping to a new port and the other one for networking capabilities. Please advice. Thanks!
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:9 (6 by maintainers)

Top Related StackOverflow Question
thanks for the discovery @REslim30 ! from testcontainers’ point of view, it is right what you said
HostConfigis already created byGenericContainer. So, doing something like it was initially proposed will override some configuration. It is also mentioned in the docsPotentially, we could add in a note there saying to opt for modifying nested objects like
authConfig,healthCheck,hostConfig,networkingConfigvolumes, instead of creating new ones as test containers might have configured its own version. We can add in an example of what to avoid and what to do instead. I can submit a PR for this