azure-docs-sdk-java/docs-ref-autogen/com.azure.json.JsonSerializ...

193 строки
15 KiB
YAML

### YamlMime:JavaType
uid: "com.azure.json.JsonSerializable"
fullName: "com.azure.json.JsonSerializable<T>"
name: "JsonSerializable<T>"
nameWithType: "JsonSerializable<T>"
summary: "Indicates that the implementing class can be serialized to and deserialized from JSON."
syntax: "public interface **JsonSerializable<T>**"
methods:
- uid: "com.azure.json.JsonSerializable.<T>fromJson(byte[])"
fullName: "com.azure.json.JsonSerializable<T>.fromJson(byte[] bytes)"
name: "fromJson(byte[] bytes)"
nameWithType: "JsonSerializable<T>.fromJson(byte[] bytes)"
summary: "Convenience method for reading a JSON byte array into an object."
modifiers:
- "static"
parameters:
- description: "The JSON byte array to read."
name: "bytes"
type: "<xref href=\"byte?alt=byte&text=byte\" data-throw-if-not-resolved=\"False\" />[]"
syntax: "public static T <T>fromJson(byte[] bytes)"
exceptions:
- description: "If an object fails to be read from the <code>bytes</code>."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html\">IOException</a>"
desc: "Convenience method for reading a JSON byte array into an object."
returns:
description: "The object that the JSON byte array represented, may return null."
type: "<xref href=\"T?alt=T&text=T\" data-throw-if-not-resolved=\"False\" />"
- uid: "com.azure.json.JsonSerializable.<T>fromJson(com.azure.json.JsonReader)"
fullName: "com.azure.json.JsonSerializable<T>.fromJson(JsonReader jsonReader)"
name: "fromJson(JsonReader jsonReader)"
nameWithType: "JsonSerializable<T>.fromJson(JsonReader jsonReader)"
summary: "Reads a JSON stream into an object."
modifiers:
- "static"
parameters:
- description: "The <xref uid=\"com.azure.json.JsonReader\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonReader\"></xref> being read."
name: "jsonReader"
type: "<xref href=\"com.azure.json.JsonReader?alt=com.azure.json.JsonReader&text=JsonReader\" data-throw-if-not-resolved=\"False\" />"
syntax: "public static T <T>fromJson(JsonReader jsonReader)"
exceptions:
- description: "If an object fails to be read from the <code>jsonReader</code>."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html\">IOException</a>"
desc: "Reads a JSON stream into an object.\n\nImplementations of <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> must define this method, otherwise an <xref uid=\"\" data-throw-if-not-resolved=\"false\" data-raw-source=\"UnsupportedOperationException\"></xref> will be thrown."
returns:
description: "The object that the JSON stream represented, may return null."
type: "<xref href=\"T?alt=T&text=T\" data-throw-if-not-resolved=\"False\" />"
- uid: "com.azure.json.JsonSerializable.<T>fromJson(java.io.InputStream)"
fullName: "com.azure.json.JsonSerializable<T>.fromJson(InputStream inputStream)"
name: "fromJson(InputStream inputStream)"
nameWithType: "JsonSerializable<T>.fromJson(InputStream inputStream)"
summary: "Convenience method for reading a JSON <xref uid=\"java.io.InputStream\" data-throw-if-not-resolved=\"false\" data-raw-source=\"InputStream\"></xref> into an object."
modifiers:
- "static"
parameters:
- description: "The JSON <xref uid=\"java.io.InputStream\" data-throw-if-not-resolved=\"false\" data-raw-source=\"InputStream\"></xref> to read."
name: "inputStream"
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html\">InputStream</a>"
syntax: "public static T <T>fromJson(InputStream inputStream)"
exceptions:
- description: "If an object fails to be read from the <code>inputStream</code>."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html\">IOException</a>"
desc: "Convenience method for reading a JSON <xref uid=\"java.io.InputStream\" data-throw-if-not-resolved=\"false\" data-raw-source=\"InputStream\"></xref> into an object."
returns:
description: "The object that the JSON <xref uid=\"java.io.InputStream\" data-throw-if-not-resolved=\"false\" data-raw-source=\"InputStream\"></xref> represented, may return null."
type: "<xref href=\"T?alt=T&text=T\" data-throw-if-not-resolved=\"False\" />"
- uid: "com.azure.json.JsonSerializable.<T>fromJson(java.io.Reader)"
fullName: "com.azure.json.JsonSerializable<T>.fromJson(Reader reader)"
name: "fromJson(Reader reader)"
nameWithType: "JsonSerializable<T>.fromJson(Reader reader)"
summary: "Convenience method for reading a JSON <xref uid=\"java.io.Reader\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Reader\"></xref> into an object."
modifiers:
- "static"
parameters:
- description: "The JSON <xref uid=\"java.io.Reader\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Reader\"></xref> to read."
name: "reader"
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/Reader.html\">Reader</a>"
syntax: "public static T <T>fromJson(Reader reader)"
exceptions:
- description: "If an object fails to be read from the <code>reader</code>."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html\">IOException</a>"
desc: "Convenience method for reading a JSON <xref uid=\"java.io.Reader\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Reader\"></xref> into an object."
returns:
description: "The object that the JSON <xref uid=\"java.io.Reader\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Reader\"></xref> represented, may return null."
type: "<xref href=\"T?alt=T&text=T\" data-throw-if-not-resolved=\"False\" />"
- uid: "com.azure.json.JsonSerializable.<T>fromJson(java.lang.String)"
fullName: "com.azure.json.JsonSerializable<T>.fromJson(String string)"
name: "fromJson(String string)"
nameWithType: "JsonSerializable<T>.fromJson(String string)"
summary: "Convenience method for reading a JSON string into an object."
modifiers:
- "static"
parameters:
- description: "The JSON string to read."
name: "string"
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/String.html\">String</a>"
syntax: "public static T <T>fromJson(String string)"
exceptions:
- description: "If an object fails to be read from the <code>string</code>."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html\">IOException</a>"
desc: "Convenience method for reading a JSON string into an object."
returns:
description: "The object that the JSON string represented, may return null."
type: "<xref href=\"T?alt=T&text=T\" data-throw-if-not-resolved=\"False\" />"
- uid: "com.azure.json.JsonSerializable.toJson(com.azure.json.JsonWriter)"
fullName: "com.azure.json.JsonSerializable<T>.toJson(JsonWriter jsonWriter)"
name: "toJson(JsonWriter jsonWriter)"
nameWithType: "JsonSerializable<T>.toJson(JsonWriter jsonWriter)"
summary: "Writes the object to the passed <xref uid=\"com.azure.json.JsonWriter\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonWriter\"></xref>."
modifiers:
- "abstract"
parameters:
- description: "Where the object's JSON will be written."
name: "jsonWriter"
type: "<xref href=\"com.azure.json.JsonWriter?alt=com.azure.json.JsonWriter&text=JsonWriter\" data-throw-if-not-resolved=\"False\" />"
syntax: "public abstract JsonWriter toJson(JsonWriter jsonWriter)"
exceptions:
- description: "If the object fails to be written to the <code>jsonWriter</code>."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html\">IOException</a>"
desc: "Writes the object to the passed <xref uid=\"com.azure.json.JsonWriter\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonWriter\"></xref>.\n\nThe contract for writing JSON to <xref uid=\"com.azure.json.JsonWriter\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonWriter\"></xref> is that the object being written will handle opening and closing its own JSON object. So, for objects calling out to other <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> objects for serialization, they'll write the field name only then pass the <xref uid=\"com.azure.json.JsonWriter\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonWriter\"></xref> to the other <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> object. This way objects writing JSON will be self-encapsulated for writing properly formatted JSON."
returns:
description: "The <xref uid=\"com.azure.json.JsonWriter\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonWriter\"></xref> where the JSON was written."
type: "<xref href=\"com.azure.json.JsonWriter?alt=com.azure.json.JsonWriter&text=JsonWriter\" data-throw-if-not-resolved=\"False\" />"
- uid: "com.azure.json.JsonSerializable.toJson(java.io.OutputStream)"
fullName: "com.azure.json.JsonSerializable<T>.toJson(OutputStream outputStream)"
name: "toJson(OutputStream outputStream)"
nameWithType: "JsonSerializable<T>.toJson(OutputStream outputStream)"
summary: "Convenience method for writing the <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> to the passed <xref uid=\"java.io.OutputStream\" data-throw-if-not-resolved=\"false\" data-raw-source=\"OutputStream\"></xref>."
modifiers:
- "default"
parameters:
- description: "The <xref uid=\"java.io.OutputStream\" data-throw-if-not-resolved=\"false\" data-raw-source=\"OutputStream\"></xref> to write the JSON to."
name: "outputStream"
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/OutputStream.html\">OutputStream</a>"
syntax: "public default void toJson(OutputStream outputStream)"
exceptions:
- description: "If the object fails to be written to the <code>outputStream</code>."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html\">IOException</a>"
desc: "Convenience method for writing the <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> to the passed <xref uid=\"java.io.OutputStream\" data-throw-if-not-resolved=\"false\" data-raw-source=\"OutputStream\"></xref>."
- uid: "com.azure.json.JsonSerializable.toJson(java.io.Writer)"
fullName: "com.azure.json.JsonSerializable<T>.toJson(Writer writer)"
name: "toJson(Writer writer)"
nameWithType: "JsonSerializable<T>.toJson(Writer writer)"
summary: "Convenience method for writing the <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> to the passed <xref uid=\"java.io.Writer\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Writer\"></xref>."
modifiers:
- "default"
parameters:
- description: "The <xref uid=\"java.io.Writer\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Writer\"></xref> to write the JSON to."
name: "writer"
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/Writer.html\">Writer</a>"
syntax: "public default void toJson(Writer writer)"
exceptions:
- description: "If the object fails to be written to the <code>writer</code>."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html\">IOException</a>"
desc: "Convenience method for writing the <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> to the passed <xref uid=\"java.io.Writer\" data-throw-if-not-resolved=\"false\" data-raw-source=\"Writer\"></xref>."
- uid: "com.azure.json.JsonSerializable.toJsonBytes()"
fullName: "com.azure.json.JsonSerializable<T>.toJsonBytes()"
name: "toJsonBytes()"
nameWithType: "JsonSerializable<T>.toJsonBytes()"
summary: "Convenience method for writing the <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> to a byte array."
modifiers:
- "default"
syntax: "public default byte[] toJsonBytes()"
exceptions:
- description: "If the object fails to be written as a byte array."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html\">IOException</a>"
desc: "Convenience method for writing the <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> to a byte array."
returns:
description: "The byte array representing the object."
type: "<xref href=\"byte?alt=byte&text=byte\" data-throw-if-not-resolved=\"False\" />[]"
- uid: "com.azure.json.JsonSerializable.toJsonString()"
fullName: "com.azure.json.JsonSerializable<T>.toJsonString()"
name: "toJsonString()"
nameWithType: "JsonSerializable<T>.toJsonString()"
summary: "Convenience method for writing the <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> to a JSON string."
modifiers:
- "default"
syntax: "public default String toJsonString()"
exceptions:
- description: "If the object fails to be written as a JSON string."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html\">IOException</a>"
desc: "Convenience method for writing the <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> to a JSON string."
returns:
description: "The JSON string representing the object."
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/String.html\">String</a>"
type: "interface"
typeParameters:
- description: "The type of the object that is JSON serializable."
name: "T"
desc: "Indicates that the implementing class can be serialized to and deserialized from JSON.\n\nSince deserialization needs to work without an instance of the class, implementing this interface it's assumed the class has a static method `fromJson(JsonReader)` that deserializes an instance of that class. The contract for reading JSON from <xref uid=\"com.azure.json.JsonReader\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonReader\"></xref> is that the initial state of the reader on call will either be a null <xref uid=\"com.azure.json.JsonToken\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonToken\"></xref> or be the <xref uid=\"com.azure.json.JsonToken\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonToken\"></xref> after the <xref uid=\"com.azure.json.JsonToken.FIELD_NAME\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonToken#FIELD_NAME\"></xref> for the object. So, for objects calling out to other <xref uid=\"com.azure.json.JsonSerializable\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonSerializable\"></xref> objects for deserialization, they'll pass the reader pointing to the token after the <xref uid=\"com.azure.json.JsonToken.FIELD_NAME\" data-throw-if-not-resolved=\"false\" data-raw-source=\"JsonToken#FIELD_NAME\"></xref>. This way objects reading JSON will be self-encapsulated for reading properly formatted JSON. And, if an error occurs during deserialization an <xref uid=\"\" data-throw-if-not-resolved=\"false\" data-raw-source=\"IllegalStateException\"></xref> should be thrown."
metadata: {}
package: "com.azure.json"
artifact: com.azure:azure-json:1.3.0