java - Problems while parsing enums using gson -


i have class this:

@jsoninclude(include.non_null) @jsonnaming(propertynamingstrategy.snakecasestrategy.class) public class vpc {     @notnull()     private string id;      @notnull()     @dynamodbmarshalling(marshallerclass = subnettypemarshaller.class)     private map<subnettype, list<string>> subnettypetoid; } 

here, subnettype enum this:

public enum subnettype {      appsubnet,      dbsubnet,      dmzsubnet; } 

now, want store above in aws dynamodb. this, need convert enum string , have written following.

public class subnettypemarshaller implements dynamodbmarshaller<map<subnettype, list<string>>> {      private gson gson = new gsonbuilder().create();      @override     public string marshall(final map<subnettype, list<string>> securitygrouptypelistmap)     {         return gson.tojson(securitygrouptypelistmap);     }      @override     public map<subnettype, list<string>> unmarshall(final class<map<subnettype, list<string>>> aclass,             final string s)     {         return gson.fromjson(s, aclass);     } } 

but doesn't work. while getting values db, following error:

java.lang.string cannot cast java.lang.enum (through reference chain: java.util.arraylist[0]->["security_group_type_to_id"])

am missing in this? searched on other posts how convert enums string using @serializedname annotation. didn't work either. have tried solution mentioned in other post, doesn't work. maybe because enum in part of map , can't annotate enum attribute inside map.

gson provides default serialization enums, if want change have build own adapter.

check gson docs registertypeadapter.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -