8000 Parse prefixed Capability values by Sigmonia · Pull Request #2418 · docker-java/docker-java · GitHub
[go: up one dir, main page]

Skip to content

Parse prefixed Capability values #2418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonCreator;

/**
* The Linux capabilities supported by Docker. The list of capabilities is defined in Docker's types.go, {@link #ALL} was added manually.
*
Expand Down Expand Up @@ -299,5 +301,11 @@ public enum Capability {
/**
* Trigger something that will wake up the system (set CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM timers).
*/
WAKE_ALARM
WAKE_ALARM;

@JsonCreator
public static Capability fromValue(String cap) {
String result = !cap.startsWith("CAP_") ? cap : cap.split("_", 2)[1];
return Capability.valueOf(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public void serializeCapability() throws Exception {
public void deserializeCapability() throws Exception {
Capability capability = JSONTestHelper.getMapper().readValue("\"ALL\"", Capability.class);
assertEquals(Capability.ALL, capability);

Capability compatibleCapability = JSONTestHelper.getMapper().readValue("\"CAP_ALL\"", Capability.class);
assertEquals(Capability.ALL, compatibleCapability);
}

@Test(expected = JsonMappingException.class)
Expand Down
0