I am reading a Json string and make it to an object using scala code:
val myInstance = (new Gson()).fromJson(t, classOf[myClass])
Everything works fine until I added a hash map in "myClass" class. Then for the following Json input (friends is a hashMap)
{"pId":"P:12345","name":"Dan Brown","friends":{"{\"firstname\":\"John\",\"lastname\":\"Smith\"}":1.0}}
Then I got the following error at "firstname" attribute as below. Does anyone have any idea? Thank you very much!
15/07/29 08:43:05 ERROR Executor: Exception in task 0.0 in stage 0.0 (TID 0)
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 51
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
    at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:186)
    at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145)
and here is myClass class:
public final class myClass extends implements Serializable {
    private static final long serialVersionUID = 11271827L;
    private String pId;
    private String name;
    private List<MyPet> pets = new ArrayList<MyPet>();
    private Map<MyName, Double> friends = new HashMap<MyName, Double>();
       :
   //some getter/setter here
}
and here is myName class:
public class MyName {
    private String firstname;
    private String lastname;
    /**
     * 
     * @return the Json string
     */
    public final String toJsonString() {
        return (new Gson()).toJson(this);
    }
    @Override
    public final String toString() {
        return toJsonString();
    }
}
 
     
    