I'm facing a problem with nested enum. So, I have an nested enum which has default values as you can see. Before there were just an enums like CDs and CMs. Now I set something like definition to every of it as you can see "Cool Ds" and etc. Currently I'm facing a problem that I can't read enums String, which is in () and I don't know how to fix it anymore. Does anyone have an idea?
package com.test.beans;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class RecordBean implements Serializable {
public enum Types {
CDs("Cool Ds"), CMs("Cool Ms");
private final String s;
private Types(String s) {
this.s=s;
}
public String getTypes(){
return s;
}
public static Types fromNumeric(int index) {
switch (index) {
default:
return null;
case 0:
return Types.CDs;
case 1:
return Types.CMs;
}
}
}
private Types type;
private float value;
public RecordBean() {
// default constructor for default instantiate
}
public RecordBean(Types type, float value) {
this.type = type;
this.value = value;
}
public Types getType() {
return type;
}
public void setType(Types type) {
this.type = type;
}
public float getValue() {
return value;
}
public void setValue(float value) {
this.value = value;
}
}
UPDATE
Error what I'm getting:
17/04/10 12:44:53 ERROR App$: Can not construct instance of com.test.beans.RecordBean$Types from String value 'Cool Ds': value not one of declared Enum instance names: CDs, CMs ]
So as you can see he is not comparing my String 'Cool Ds' with enums String in brackets but with pure enum or CDs and CMs
My USE-CASE is like this. I'm working spark streaming where data are incoming to my RecordBean class and where are comparing to my enum type. Because in database are changed types from CMs to Cool Ms I needed to change the same in my app by adding definition to Enum. Afterwards I couldn't accomplish part where app will process enum like CMs and read its definition or Cool Ms