title: GSON fails parsing JSON with string space
body: <p>I have the following object:</p>
  
  <pre><code>public class ParameterWrapper&lt;T&gt; {
  
      private String type;
  
      private T value;
  
      public ParameterWrapper(String type, T value) {
          this.type = type;
          this.value = value;
      }
  
      public String getType() {
          return type;
      }
  
      public void setType(String type) {
          this.type = type;
      }
  
      public T getValue() {
          return value;
      }
  
      public void setValue(T value) {
          this.value = value;
      }
  }
  </code></pre>
  
  <p>I am serializing it into JSON using the Gson library. When <code>value</code> contains a string with no spaces, it works perfectly. When <code>value</code> contains a string with spaces, I see the following exception:</p>
  
  <blockquote>
    <p>com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated object at line 1 column 28</p>
  </blockquote>
  
  <p>For the following JSON:</p>
  
  <pre><code>{"Plaintext":{"type":"String","value":"hello there"},"Key":{"type":"Number","value":"1"},"SINGLE_FUNCTION":{"value":"1-0"}}
  </code></pre>
  
  <p>However with the following:</p>
  
  <pre><code>{"Plaintext":{"type":"String","value":"hellothere"},"Key":{"type":"Number","value":"1"},"SINGLE_FUNCTION":{"value":"1-0"}}
  </code></pre>
  
  <p>The JSON is parsed successfully. Is this a known issue? I've ran the JSON through a validator and it is perfectly fine.</p>
  
  <p>Edit:</p>
  
  <p>The vagueness of the question wasn't unnoticed. I was hoping this was an existing issue. The application is huge, which is why prying out a small, compilable example is difficult, but I'll do what I can!</p>
  
  <p>OKAY. So firstly, the below JSON is send to my controller:</p>
  
  <pre><code>@RequestMapping("/update-state")
  public
  @ResponseBody
  String updateState(@RequestParam(value = "algorithmId") String algorithmId,
                     @RequestParam(value = "state") String state) throws InvalidParameterException {
  
      Algorithm algorithm = algorithmService.getAlgorithmById(Integer.parseInt(algorithmId));
      algorithm.execute(executorService.parseAlgorithmState(state));
  
      return gsonBuilder.toJson(algorithm.getState().getParameterMap());
  }
  </code></pre>
  
  <p>On the call to <code>parseAlgorithmState(state)</code>, it moves down to this method:</p>
  
  <pre><code>@Override
  public AlgorithmState parseAlgorithmState(String json) throws InvalidParameterException {
      Gson gson = new Gson();
      Map keyValueMap = (Map) gson.fromJson(json.trim(), Object.class);
      ...
  </code></pre>
  
  <p>The line <code>Map keyValueMap = (Map) gson.fromJson(json.trim(), Object.class);</code> is where the exception is initially occurring.</p>