Class JsonParser


  • public final class JsonParser
    extends java.lang.Object
    A JSON Parser based on the GSON JsonReader.

    The parsing is almost identical to the normal parser provided by GSON with these changes: it never uses "lenient" mode, it rejects duplicated map keys and it rejects strings with invalid UTF16 characters.

    The implementation is adapted from almost identical to GSON's TypeAdapters.JSON_ELEMENT.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long getParsedNumberAsLongOrThrow​(java.lang.Number number)
      Converts a parsed Number into a long if it contains a valid long value.
      static boolean isValidString​(java.lang.String s)  
      static com.google.gson.JsonElement parse​(java.lang.String json)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isValidString

        public static boolean isValidString​(java.lang.String s)
      • parse

        public static com.google.gson.JsonElement parse​(java.lang.String json)
                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • getParsedNumberAsLongOrThrow

        public static long getParsedNumberAsLongOrThrow​(java.lang.Number number)
        Converts a parsed Number into a long if it contains a valid long value.

        Requires that number is part of a output produced by parse(java.lang.String).

        Throws:
        java.lang.NumberFormatException - if number does not contain a valid long value.