Code example for JsonReader

Methods: peek

0
   * Takes a reader in any state and returns the next value as a JsonElement. 
   */ 
  public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try { 
      reader.peek();
      isEmpty = false;
      return TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (EOFException e) {
      /* 
       * For compatibility with JSON 1.5 and earlier, we return a JsonNull for 
       * empty documents instead of throwing. 
       */ 
      if (isEmpty) {
        return JsonNull.INSTANCE;
      } 
      // The stream ended prematurely so it is likely a syntax error. 
      throw new JsonSyntaxException(e);
    } catch (MalformedJsonException e) {
      throw new JsonSyntaxException(e);