Skip to content

Commit 33a58b6

Browse files
Parse prefixed Capability values (#2418)
Co-authored-by: Eddú Meléndez Gonzales <eddu.melendez@gmail.com>
1 parent 1f1e60d commit 33a58b6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

docker-java-api/src/main/java/com/github/dockerjava/api/model/Capability.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.dockerjava.api.model;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
35
/**
46
* The Linux capabilities supported by Docker. The list of capabilities is defined in Docker's types.go, {@link #ALL} was added manually.
57
*
@@ -299,5 +301,11 @@ public enum Capability {
299301
/**
300302
* Trigger something that will wake up the system (set CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM timers).
301303
*/
302-
WAKE_ALARM
304+
WAKE_ALARM;
305+
306+
@JsonCreator
307+
public static Capability fromValue(String cap) {
308+
String result = !cap.startsWith("CAP_") ? cap : cap.split("_", 2)[1];
309+
return Capability.valueOf(result);
310+
}
303311
}

docker-java/src/test/java/com/github/dockerjava/api/model/CapabilityTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public void serializeCapability() throws Exception {
1818
public void deserializeCapability() throws Exception {
1919
Capability capability = JSONTestHelper.getMapper().readValue("\"ALL\"", Capability.class);
2020
assertEquals(Capability.ALL, capability);
21+
22+
Capability compatibleCapability = JSONTestHelper.getMapper().readValue("\"CAP_ALL\"", Capability.class);
23+
assertEquals(Capability.ALL, compatibleCapability);
2124
}
2225

2326
@Test(expected = JsonMappingException.class)

0 commit comments

Comments
 (0)