public enum ClusterType {
TEMPERATURE("0402"),
HUMIDITY("0405"),
ENERGY_DETAILS("0702"),
SMART_SOCKET_STATUS("0006"),
ALARMED("0500");
private String value = null;
ClusterType(String byteStr) {
this.value = byteStr;
}
@JsonCreator
public static ClusterType fromValue(final String val){
return (ClusterType) CollectionUtils.find(Arrays.asList(ClusterType.values()), new Predicate() {
public boolean evaluate(Object object) {
ClusterType candidate = (ClusterType) object;
return StringUtils.equals(candidate.value, val);
}
});
}
@JsonValue
public String getValue(){
return value;
}
public byte[] get() {
return ByteUtils.hexStringToByteArray(value);
}
public boolean equals(String cluster) {
return StringUtils.equals(cluster, value);
}
}
Run Code Online (Sandbox Code Playgroud)
我有上面的枚举
@JsonValue public String getValue(){return value; …