Serialization Class

  • java.lang.Object
    • com.microsoft.bot.schema.Serialization

public final class Serialization

Serialization helpers.

Method Summary

Modifier and Type Method and Description
static java.util.concurrent.CompletableFuture<R> <R>futureGetAs(Object obj, Class<R> classType)

Deserializes an object to a type as a future to ease CompletableFuture chaining.

static T <T>convert(Object source, Class<T> toClass)

Converts an input object to another type.

static T <T>getAs(Object obj, Class<T> classType)

Deserialize a value.

static T <T>safeGetAs(Object obj, Class<T> classType)

Deserialize a value.

static T <T>treeToValue(JsonNode src, Class<T> cls)
static com.fasterxml.jackson.databind.JsonNode asNode(boolean b)
static com.fasterxml.jackson.databind.JsonNode asNode(byte b)
static com.fasterxml.jackson.databind.JsonNode asNode(double d)
static com.fasterxml.jackson.databind.JsonNode asNode(float f)
static com.fasterxml.jackson.databind.JsonNode asNode(int i)
static com.fasterxml.jackson.databind.JsonNode asNode(String s)
static com.fasterxml.jackson.databind.JsonNode asNode(long l)
static com.fasterxml.jackson.databind.JsonNode asNode(short s)
static java.lang.Object clone(Object obj)
static com.fasterxml.jackson.databind.node.ArrayNode createArrayNode()

Creates an ArrayNode.

static com.fasterxml.jackson.databind.node.ObjectNode createObjectNode()

Creates an ObjectNode.

static com.fasterxml.jackson.databind.JsonNode jsonToTree(String json)

Parses a JSON document.

static com.fasterxml.jackson.databind.JsonNode objectToTree(Object obj)

Convert Object to JsonNode.

static java.lang.String toString(Object source)

Convert an object to a JSON string.

static java.lang.String toStringSilent(Object source)

Convert an object to a JSON string.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Method Details

<R>futureGetAs

public static CompletableFuture futureGetAs(Object obj, Class classType)

Deserializes an object to a type as a future to ease CompletableFuture chaining.

Parameters:

obj - The object to deserialize.
classType - Class information to convert to.

Returns:

A CompletableFuture containing the value or exception for an error.

<T>convert

public static T convert(Object source, Class toClass)

Converts an input object to another type.

Parameters:

source - The object to convert.
toClass - The class to convert to.

Returns:

The converted object, or null.

<T>getAs

public static T getAs(Object obj, Class classType)

Deserialize a value.

Parameters:

obj - The object to deserialize.
classType - The class type to convert to.

Returns:

A deserialized POJO, or null for error.

<T>safeGetAs

public static T safeGetAs(Object obj, Class classType)

Deserialize a value.

Parameters:

obj - The object to deserialize.
classType - The class type to convert to.

Returns:

A deserialized POJO, or null.

Throws:

com.fasterxml.jackson.core.JsonProcessingException - The JSON processing exception.

<T>treeToValue

public static T treeToValue(JsonNode src, Class cls)

Parameters:

src - The source JsonNode
cls - The Class to Map

Returns:

the result of the mapping

asNode

public static JsonNode asNode(boolean b)

Parameters:

b - The boolean to convert to a JsonNode

Returns:

JsonNode

asNode

public static JsonNode asNode(byte b)

Parameters:

b - The byte to convert to a JsonNode

Returns:

JsonNode

asNode

public static JsonNode asNode(double d)

Parameters:

d - The double to convert to a JsonNode

Returns:

JsonNode

asNode

public static JsonNode asNode(float f)

Parameters:

f - The float to convert to a JsonNode

Returns:

JsonNode

asNode

public static JsonNode asNode(int i)

Parameters:

i - The int to convert to a JsonNode

Returns:

JsonNode

asNode

public static JsonNode asNode(String s)

Parameters:

s - The string to convert to a JsonNode

Returns:

JsonNode

asNode

public static JsonNode asNode(long l)

Parameters:

l - The long to convert to a JsonNode

Returns:

JsonNode

asNode

public static JsonNode asNode(short s)

Parameters:

s - The short to convert to a JsonNode

Returns:

JsonNode

clone

public static Object clone(Object obj)

Parameters:

obj - The Object to clone

Returns:

Object The cloned Object

createArrayNode

public static ArrayNode createArrayNode()

Creates an ArrayNode.

Returns:

ArrayNode.

createObjectNode

public static ObjectNode createObjectNode()

Creates an ObjectNode.

Returns:

ObjectNode.

jsonToTree

public static JsonNode jsonToTree(String json)

Parses a JSON document.

Parameters:

json - The JSON to parse.

Returns:

A JsonNode containing the node tree.

Throws:

java.io.IOException - Error parsing json.

objectToTree

public static JsonNode objectToTree(Object obj)

Convert Object to JsonNode.

Parameters:

obj - The object to convert.

Returns:

The JsonNode for the object tree.

toString

public static String toString(Object source)

Convert an object to a JSON string.

Parameters:

source - The object to convert.

Returns:

The JSON string value.

Throws:

com.fasterxml.jackson.core.JsonProcessingException - Error converting to JSON

toStringSilent

public static String toStringSilent(Object source)

Convert an object to a JSON string.

Parameters:

source - The object to convert.

Returns:

The JSON string value.

Applies to