title: Validating JSON using GSON in java
body: <p>I'm using GSON to validate a string which is in JSON format:</p>
  
  <pre><code>String json="{'hashkey':{'calculatedHMAC':'f7b5addd27a221b216068cddb9abf1f06b3c0e1c','secretkey':'12345'},operation':'read','attributes':['name','id'],'otid':'12'}";
  Gson gson=new Gson();
  Response resp = new Response();
  RequestParameters para = null;
  try{
      para = gson.fromJson(json, RequestParameters.class);
  }catch(Exception e){
      System.out.println("invalid json format");
  }
  </code></pre>
  
  <p>Its doing good but when I remove the quotes like below, I have removed from hashkey:</p>
  
  <pre><code>"{hashkey':{'calculatedHMAC':'f7b5addd27a221b216068cddb9abf1f06b3c0e1c','secretkey':'12345'},operation':'read','attributes':['name','id'],'otid':'12'}"
  </code></pre>
  
  <p>It's still validating it as a proper JSONformat and not throwing any exception and not going in catch body. Any reason why it is doing so? How would I solve this?</p>
  
  <p>RequestParameters class:</p>
  
  <pre><code>public class RequestParameters {
      HashKey hashkey;
      String operation;
      int count;
      int otid;
      String[] attributes;
  
  }
  </code></pre>