Skip to content

Commit a06e9dd

Browse files
committed
Change deserialiser
1 parent d77f6bc commit a06e9dd

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed
Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package com.github.dockerjava.api.model;
22

3-
import com.fasterxml.jackson.annotation.JsonProperty;
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
6+
import javax.annotation.Nonnull;
7+
import java.util.HashMap;
8+
import java.util.Map;
49

510
/**
611
* https://github.com/moby/moby/blob/master/api/types/swarm/swarm.go#L174-L188
@@ -9,26 +14,40 @@
914
*/
1015
public enum LocalNodeState {
1116

12-
@JsonProperty("inactive")
13-
INACTIVE,
14-
15-
@JsonProperty("pending")
16-
PENDING,
17-
18-
@JsonProperty("active")
19-
ACTIVE,
20-
21-
@JsonProperty("error")
22-
ERROR,
23-
24-
@JsonProperty("locked")
25-
LOCKED,
17+
INACTIVE("inactive"),
18+
PENDING("pending"),
19+
ACTIVE("active"),
20+
ERROR("error"),
21+
LOCKED("locked"),
2622

2723
/**
2824
* Can not construct instance of com.github.dockerjava.api.model.LocalNodeState
2925
* from String value '': value not one of declared Enum instance names: [error, locked, inactive, active, pending]
3026
*/
31-
@JsonProperty("")
32-
EMPTY
27+
EMPTY("");
28+
29+
private static final Map<String, LocalNodeState> TYPES = new HashMap<>();
30+
31+
static {
32+
for (LocalNodeState t : values()) {
33+
TYPES.put(t.name().toLowerCase(), t);
34+
}
35+
}
36+
37+
private String value;
38+
39+
LocalNodeState(@Nonnull String value) {
40+
this.value = value;
41+
}
42+
43+
@JsonValue
44+
public String getValue() {
45+
return value;
46+
}
47+
48+
@JsonCreator
49+
public static LocalNodeState forValue(String s) {
50+
return TYPES.get(s);
51+
}
3352

3453
}

src/main/java/com/github/dockerjava/api/model/SwarmInfo.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
@JsonIgnoreProperties(ignoreUnknown = true)
1919
@JsonInclude(JsonInclude.Include.NON_NULL)
2020
public class SwarmInfo implements Serializable {
21-
22-
public static final Long serialVersionUID = 1L;
21+
public static final long serialVersionUID = 1L;
2322

2423
/**
2524
* @since 1.24
@@ -34,8 +33,6 @@ public class SwarmInfo implements Serializable {
3433
private String nodeAddr;
3534

3635
/**
37-
* Not {@link LocalNodeState}, because in swarm it string and we got error:
38-
*
3936
* @since 1.24
4037
*/
4138
@JsonProperty("LocalNodeState")

0 commit comments

Comments
 (0)