import com.google.gson.Gson;import com.google.gson.reflect.TypeToken;import java.util.EnumSet;public class Test2 {enum Color { red, blue, green, yellow, thistle }public static void main(String[] args) throws Exception {Gson gson = new Gson();EnumSet<Color> foo = EnumSet.of(Color.blue, Color.red);String json = gson.toJson(foo);EnumSet<Color> bar = (EnumSet<Color>)gson.fromJson(json, new TypeToken<EnumSet<Color>>() {}.getType());System.out.printf("foo: " + foo + "\nbar: " + bar + '\n');}}
Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashSet cannot be cast to java.util.EnumSetat com.nf.tests.exp.Test2.main(Test2.java:line in red)