title: How to serialize and deserialize objects that contains HashMaps and Pairs using GSON
body: <p>I have this Hashmap <code>Map&lt;Pair&lt;String,String&gt;,Map&lt;String,String&gt;&gt; pathData = new HashMap&lt;&gt;();</code> as an attribute of other object (Tour_Object) and i'm trying to serialize/deserialize it in json using GSON library.</p>
  
  <pre><code>public static String setTourToJson(Tour_Object tourObject)
  {
      Gson gson = new Gson();
      return gson.toJson(tourObject);
  }
  
  public static Tour_Object getTourFromJson(String JsonString)
  {
      Gson gson = new Gson();
      return gson.fromJson(JsonString, new TypeToken&lt;Tour_Object&gt;() {
      }.getType());
  }
  </code></pre>
  
  <p>The following exception is thrown when I proceed to the deserialization:</p>
  
  <pre><code>04-19 11:18:49.449 29076-29076/abff.fxguide E/AndroidRuntime: FATAL EXCEPTION: main
  Process: abff.fxguide, PID: 29076
  com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 100 path $.pathData.
  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
  at com.google.gson.Gson.fromJson(Gson.java:879)
  at com.google.gson.Gson.fromJson(Gson.java:844)
  at com.google.gson.Gson.fromJson(Gson.java:793)
  at com.google.gson.Gson.fromJson(Gson.java:765)
  at abff.fxguide.Tour_Helper.getTourFromJson(Tour_Helper.java:311)
  at abff.fxguide.Tour_All.showTourDetails(Tour_All.java:266)
  at abff.fxguide.Tour_All$8.onClick(Tour_All.java:370)
  at android.view.View.performClick(View.java:4856)
  at android.view.View$PerformClick.run(View.java:19956)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:211)
  at android.app.ActivityThread.main(ActivityThread.java:5389)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
  Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 100 path $.pathData.
  at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:388)
  at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:183)
  at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145)
  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)
  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:116)
  at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:216)
  at com.google.gson.Gson.fromJson(Gson.java:879) 
  at com.google.gson.Gson.fromJson(Gson.java:844) 
  at com.google.gson.Gson.fromJson(Gson.java:793) 
  at com.google.gson.Gson.fromJson(Gson.java:765) 
  at abff.fxguide.Tour_Helper.getTourFromJson(Tour_Helper.java:311) 
  at abff.fxguide.Tour_All.showTourDetails(Tour_All.java:266) 
  at abff.fxguide.Tour_All$8.onClick(Tour_All.java:370) 
  at android.view.View.performClick(View.java:4856) 
  at android.view.View$PerformClick.run(View.java:19956) 
  at android.os.Handler.handleCallback(Handler.java:739) 
  at android.os.Handler.dispatchMessage(Handler.java:95) 
  at android.os.Looper.loop(Looper.java:211) 
  at android.app.ActivityThread.main(ActivityThread.java:5389) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at java.lang.reflect.Method.invoke(Method.java:372) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
  </code></pre>
  
  <p>I would like to know if the main object (Tour_Object) is deserializable as shown in <code>getTourFromJson(String JsonString)</code> when using attributes like pathData?</p>