Class GsonJsonProvider

java.lang.Object
com.azure.core.serializer.json.gson.GsonJsonProvider
All Implemented Interfaces:
com.azure.json.JsonProvider

public final class GsonJsonProvider extends Object implements com.azure.json.JsonProvider
GSON-based implementation of JsonProvider.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of GsonJsonProvider.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.azure.json.JsonReader
    createReader(byte[] json, com.azure.json.JsonOptions options)
    Creates an instance of JsonReader that reads a byte[].
    com.azure.json.JsonReader
    createReader(com.google.gson.stream.JsonReader reader, com.azure.json.JsonOptions options)
    Creates an instance of JsonReader wrapping a GSON JsonReader.
    com.azure.json.JsonReader
    createReader(InputStream json, com.azure.json.JsonOptions options)
    Creates an instance of JsonReader that reads a InputStream.
    com.azure.json.JsonReader
    createReader(Reader json, com.azure.json.JsonOptions options)
    Creates an instance of JsonReader that reads a Reader.
    com.azure.json.JsonReader
    createReader(String json, com.azure.json.JsonOptions options)
    Creates an instance of JsonReader that reads a String.
    com.azure.json.JsonWriter
    createWriter(com.google.gson.stream.JsonWriter writer)
    Creates an instance of JsonWriter wrapping a GSON JsonWriter.
    com.azure.json.JsonWriter
    createWriter(OutputStream json, com.azure.json.JsonOptions options)
    Creates an instance of JsonWriter that writes to an OutputStream.
    com.azure.json.JsonWriter
    createWriter(Writer json, com.azure.json.JsonOptions options)
    Creates an instance of JsonWriter that writes to an Writer.
    static com.google.gson.TypeAdapterFactory
    Returns a GSON TypeAdapterFactory that allows for com.azure.json implementations to handle deserialization and serialization of JsonSerializable types within a GSON context.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GsonJsonProvider

      public GsonJsonProvider()
      Creates an instance of GsonJsonProvider.
  • Method Details

    • createReader

      public com.azure.json.JsonReader createReader(byte[] json, com.azure.json.JsonOptions options) throws IOException
      Description copied from interface: com.azure.json.JsonProvider
      Creates an instance of JsonReader that reads a byte[].
      Specified by:
      createReader in interface com.azure.json.JsonProvider
      Parameters:
      json - The JSON represented as a byte[].
      options - JsonOptions to configure the creation of the JsonReader.
      Returns:
      A new instance of JsonReader.
      Throws:
      IOException - If a JsonReader cannot be instantiated.
    • createReader

      public com.azure.json.JsonReader createReader(String json, com.azure.json.JsonOptions options) throws IOException
      Description copied from interface: com.azure.json.JsonProvider
      Creates an instance of JsonReader that reads a String.
      Specified by:
      createReader in interface com.azure.json.JsonProvider
      Parameters:
      json - The JSON represented as a String.
      options - JsonOptions to configure the creation of the JsonReader.
      Returns:
      A new instance of JsonReader.
      Throws:
      IOException - If a JsonReader cannot be instantiated.
    • createReader

      public com.azure.json.JsonReader createReader(InputStream json, com.azure.json.JsonOptions options) throws IOException
      Description copied from interface: com.azure.json.JsonProvider
      Creates an instance of JsonReader that reads a InputStream.
      Specified by:
      createReader in interface com.azure.json.JsonProvider
      Parameters:
      json - The JSON represented as a InputStream.
      options - JsonOptions to configure the creation of the JsonReader.
      Returns:
      A new instance of JsonReader.
      Throws:
      IOException - If a JsonReader cannot be instantiated.
    • createReader

      public com.azure.json.JsonReader createReader(Reader json, com.azure.json.JsonOptions options) throws IOException
      Description copied from interface: com.azure.json.JsonProvider
      Creates an instance of JsonReader that reads a Reader.
      Specified by:
      createReader in interface com.azure.json.JsonProvider
      Parameters:
      json - The JSON represented as a Reader.
      options - JsonOptions to configure the creation of the JsonReader.
      Returns:
      A new instance of JsonReader.
      Throws:
      IOException - If a JsonReader cannot be instantiated.
    • createReader

      public com.azure.json.JsonReader createReader(com.google.gson.stream.JsonReader reader, com.azure.json.JsonOptions options)
      Creates an instance of JsonReader wrapping a GSON JsonReader.
      Parameters:
      reader - The JsonReader parsing JSON.
      options - The options used to create the reader.
      Returns:
      A JsonReader wrapping the JsonReader.
      Throws:
      NullPointerException - If reader is null.
    • createWriter

      public com.azure.json.JsonWriter createWriter(OutputStream json, com.azure.json.JsonOptions options) throws IOException
      Description copied from interface: com.azure.json.JsonProvider
      Creates an instance of JsonWriter that writes to an OutputStream.
      Specified by:
      createWriter in interface com.azure.json.JsonProvider
      Parameters:
      json - The JSON represented as an OutputStream.
      options - JsonOptions to configure the creation of the JsonWriter.
      Returns:
      A new instance of JsonWriter.
      Throws:
      IOException - If a JsonReader cannot be instantiated.
    • createWriter

      public com.azure.json.JsonWriter createWriter(Writer json, com.azure.json.JsonOptions options) throws IOException
      Description copied from interface: com.azure.json.JsonProvider
      Creates an instance of JsonWriter that writes to an Writer.
      Specified by:
      createWriter in interface com.azure.json.JsonProvider
      Parameters:
      json - The JSON represented as an Writer.
      options - JsonOptions to configure the creation of the JsonWriter.
      Returns:
      A new instance of JsonWriter.
      Throws:
      IOException - If a JsonReader cannot be instantiated.
    • createWriter

      public com.azure.json.JsonWriter createWriter(com.google.gson.stream.JsonWriter writer)
      Creates an instance of JsonWriter wrapping a GSON JsonWriter.
      Parameters:
      writer - The JsonWriter writing JSON.
      Returns:
      A JsonWriter wrapping the JsonWriter.
      Throws:
      NullPointerException - If writer is null.
    • getJsonSerializableTypeAdapterFactory

      public static com.google.gson.TypeAdapterFactory getJsonSerializableTypeAdapterFactory()
      Returns a GSON TypeAdapterFactory that allows for com.azure.json implementations to handle deserialization and serialization of JsonSerializable types within a GSON context.

      Use the TypeAdapterFactory returned by this method when creating your Gson with GsonBuilder to have GSON support JsonSerializable types.

      Returns:
      A GSON TypeAdapterFactory that handles deserialization and serialization of JsonSerializable types.