你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

JsonSerializable 类

  • java.lang.Object
    • com.microsoft.azure.cosmosdb.JsonSerializable

public class JsonSerializable

表示可在 Azure Cosmos DB 数据库服务中序列化为 JSON 的基本资源。

构造函数摘要

构造函数 说明
JsonSerializable()
JsonSerializable(String jsonString)

构造函数。

JsonSerializable(String jsonString, ObjectMapper objectMapper)

构造函数。

方法摘要

修饰符和类型 方法和描述
Object get(String propertyName)

获取 Object 的属性值。

Boolean getBoolean(String propertyName)

获取一个布尔值。

Collection<ObjectNode> getCollection(String propertyName)

获取 JSONObject 集合。

<T> Collection<T> getCollection(String propertyName, Class<T> c)

获取对象集合。

Double getDouble(String propertyName)

获取双精度值。

HashMap<String, Object> getHashMap()

返回 hashMap 中 jsonObject) (属性包

Integer getInt(String propertyName)

获取整数值。

<T> List<T> getList(String propertyName, Class<T> c)

获取对象 List。

Logger getLogger()
Long getLong(String propertyName)

获取一个长值。

ObjectMapper getMapper()
ObjectNode getObject(String propertyName)

获取 JSONObject。

<T> T getObject(String propertyName, Class<T> c)

获取对象值。

Object getObjectByPath(List<String> propertyNames)

获取由构成路径的属性名称数组标识的属性的值。

String getString(String propertyName)

获取字符串值。

boolean has(String propertyName)

检查是否存在属性。

void remove(String propertyName)

按 propertyName 删除值。

<T> void set(String propertyName, T value)

设置属性的值。

String toJson()

转换为 JSON 字符串。

String toJson(SerializationFormattingPolicy formattingPolicy)

转换为 JSON 字符串。

<T> T toObject(Class<T> c)

) 仅支持将 转换为对象 (POJO 和 JSONObject。

String toString()

获取属性包的简单字符串表示形式。

若要正确转换为 json 并包含默认值,请使用 toJson()

构造函数详细信息

JsonSerializable

protected JsonSerializable()

JsonSerializable

protected JsonSerializable(String jsonString)

构造函数。

参数:

jsonString - 表示 JsonSerializable 的 json 字符串。

JsonSerializable

protected JsonSerializable(String jsonString, ObjectMapper objectMapper)

构造函数。

参数:

jsonString - 表示 JsonSerializable 的 json 字符串。
objectMapper - 自定义对象映射器

方法详细信息

get

public Object get(String propertyName)

获取 Object 的属性值。

参数:

propertyName - 要获取的属性。

返回:

属性的值。

getBoolean

public Boolean getBoolean(String propertyName)

获取一个布尔值。

参数:

propertyName - 要获取的属性。

返回:

布尔值。

getCollection

public Collection getCollection(String propertyName)

获取 JSONObject 集合。

参数:

propertyName - 要获取的属性。

返回:

JSONObject 集合。

getCollection

public Collection getCollection(String propertyName, Class c)

获取对象集合。

参数:

propertyName - 要获取的属性
c - 对象的类。 如果 c 是 POJO 类,则它必须是 (的成员,而不是匿名或本地) 和静态成员。

返回:

对象集合。

getDouble

public Double getDouble(String propertyName)

获取双精度值。

参数:

propertyName - 要获取的属性。

返回:

双精度值。

getHashMap

public HashMap getHashMap()

返回 hashMap 中 jsonObject) (属性包

返回:

HashMap。

getInt

public Integer getInt(String propertyName)

获取整数值。

参数:

propertyName - 要获取的属性。

返回:

布尔值

getList

public List getList(String propertyName, Class c)

获取对象 List。

参数:

propertyName - 要获取的属性
c - 对象的类。 如果 c 是 POJO 类,则它必须是 (的成员,而不是匿名或本地) 和静态成员。

返回:

对象集合。

getLogger

protected Logger getLogger()

getLong

public Long getLong(String propertyName)

获取一个长值。

参数:

propertyName - 要获取的属性。

返回:

long 值

getMapper

protected ObjectMapper getMapper()

getObject

public ObjectNode getObject(String propertyName)

获取 JSONObject。

参数:

propertyName - 要获取的属性。

返回:

JSONObject。

getObject

public T getObject(String propertyName, Class c)

获取对象值。

参数:

propertyName - 要获取的属性。
c - 对象的类。 如果 c 是 POJO 类,则它必须是 (的成员,而不是匿名或本地) 和静态成员。

返回:

对象值。

getObjectByPath

public Object getObjectByPath(List propertyNames)

获取由构成路径的属性名称数组标识的属性的值。

参数:

propertyNames - 构成要获取的属性的路径的 。

返回:

属性的值。

getString

public String getString(String propertyName)

获取字符串值。

参数:

propertyName - 要获取的属性。

返回:

字符串值。

has

public boolean has(String propertyName)

检查是否存在属性。

参数:

propertyName - 要查找的属性。

返回:

如果属性存在,则为 true。

remove

public void remove(String propertyName)

按 propertyName 删除值。

参数:

propertyName - 要删除的 属性。

set

public void set(String propertyName, T value)

设置属性的值。

参数:

propertyName - 要设置的属性。
value - 属性的值。

toJson

public String toJson()

转换为 JSON 字符串。

返回:

JSON 字符串。

toJson

public String toJson(SerializationFormattingPolicy formattingPolicy)

转换为 JSON 字符串。

参数:

formattingPolicy - 要使用的格式设置策略。

返回:

JSON 字符串。

toObject

public T toObject(Class c)

) 仅支持将 转换为对象 (POJO 和 JSONObject。

参数:

c - 对象的 类,POJO 类或 JSONObject。 如果 c 是 POJO 类,则它必须是 (成员,而不是匿名或本地) 和静态成员。

返回:

POJO。

toString

public String toString()

获取属性包的简单字符串表示形式。

若要正确转换为 json 并包含默认值,请使用 toJson()

返回:

属性包的字符串表示形式。

适用于