Skip to content

Commit ef46636

Browse files
committed
Tolerate Podman's response to docker context ls
In Spring Boot 3.x with Jackson 2, a null (or missing) value for a primitive would be mapped to the primitive's default value. In Jackson 3, the default behavior is to fail instead. This causes a failure when trying to deserialize Podman's `docker context ls response` as it is not in the expected format and has no entry for `current` that's mapped to a boolean. This commit disables FAIL_ON_NULL_FOR_PRIMITIVES to restore the behavior that we had with Jackson 2 in Spring Boot 3.x. Closes gh-47971
1 parent 160e34e commit ef46636

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerCliContextResponse.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616

1717
package org.springframework.boot.docker.compose.core;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
/**
2022
* Response from {@link DockerCliCommand.Context docker context}.
2123
*
2224
* @param name the name of the context
2325
* @param current if the context is the current one
24-
* @param dockerEndpoint the endpoint of the docker daemon
26+
* @param dockerEndpoint the endpoint of the docker daemon, or {@code null} if not known
2527
* @author Moritz Halbritter
2628
* @author Andy Wilkinson
2729
* @author Phillip Webb
2830
*/
29-
record DockerCliContextResponse(String name, boolean current, String dockerEndpoint) {
31+
record DockerCliContextResponse(String name, boolean current, @Nullable String dockerEndpoint) {
3032

3133
}

core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerJson.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ final class DockerJson {
3737
.defaultLocale(Locale.ENGLISH)
3838
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
3939
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
40+
.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
4041
.build();
4142

4243
private DockerJson() {

core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerCliContextResponseTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,13 @@ void deserializeJson() throws IOException {
4444
assertThat(response).isEqualTo(expected);
4545
}
4646

47+
@Test
48+
void deserializePodmanJson() throws IOException {
49+
String json = new ClassPathResource("docker-context-podman.json", getClass())
50+
.getContentAsString(StandardCharsets.UTF_8);
51+
DockerCliContextResponse response = DockerJson.deserialize(json, DockerCliContextResponse.class);
52+
DockerCliContextResponse expected = new DockerCliContextResponse("podman-machine-default", false, null);
53+
assertThat(response).isEqualTo(expected);
54+
}
55+
4756
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Name": "podman-machine-default",
3+
"URI": "ssh://core@127.0.0.1:55599/run/user/501/podman/podman.sock",
4+
"Identity": "/Users/user/.local/share/containers/podman/machine/machine",
5+
"IsMachine": true,
6+
"Default": false,
7+
"ReadWrite": true
8+
}

0 commit comments

Comments
 (0)