question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) on withCreateContainerCmdModifier and withNetwork

See original GitHub issue

I 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:open
  • Created a year ago
  • Reactions:4
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eddumelendezcommented, Sep 9, 2022

thanks for the discovery @REslim30 ! from testcontainers’ point of view, it is right what you said HostConfig is already created by GenericContainer. So, doing something like it was initially proposed will override some configuration. It is also mentioned in the docs

Any customizations you make using withCreateContainerCmdModifier will be applied on top of the container definition that Testcontainers creates, but before it is created.

0reactions
REslim30commented, Sep 13, 2022

Potentially, we could add in a note there saying to opt for modifying nested objects like authConfig, healthCheck, hostConfig, networkingConfig volumes, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Null key for a Map not allowed in JSON (use a converting ...
I was using GenericContainer below and encounter issue. Caused by: org.testcontainers.shaded.com.fasterxml.jackson.databind.JsonMappingException: Null key ...
Read more >
Null key for a Map not allowed in JSON (use a converting ...
core.JsonGenerationException : Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) at com.fasterxml.jackson.
Read more >
Jackson - Working with Maps and nulls - Baeldung
How to serialize Maps with a null key or null values using Jackson. ... for a Map not allowed in JSON (use a...
Read more >
DMN - Null Key for a map not allowed in Json Error
Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) (through reference chain: java.util.ArrayList[0]->java.util.
Read more >
Error Creating Tickets - Could not write JSON: Null key for a ...
JsonGenerationException : Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) The ticket will actually be created ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found