Package com.azure.data.cosmos
Class JsonSerializable
- java.lang.Object
-
- com.azure.data.cosmos.JsonSerializable
-
- Direct Known Subclasses:
CompositePath
,ConflictResolutionPolicy
,ConsistencyPolicy
,DatabaseAccountLocation
,ExcludedPath
,IncludedPath
,Index
,IndexingPolicy
,PartitionKeyDefinition
,Resource
,SpatialSpec
,SqlParameter
,SqlQuerySpec
,UniqueKey
,UniqueKeyPolicy
public class JsonSerializable extends Object
Represents a base resource that can be serialized to JSON in the Azure Cosmos DB database service.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JsonSerializable()
protected
JsonSerializable(String jsonString)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
get(String propertyName)
Gets a property value as Object.Boolean
getBoolean(String propertyName)
Gets a boolean value.<T> Collection<T>
getCollection(String propertyName, Class<T> c, boolean... convertFromCamelCase)
Gets an object collection.Double
getDouble(String propertyName)
Gets a double value.Integer
getInt(String propertyName)
Gets an integer value.<T> List<T>
getList(String propertyName, Class<T> c, boolean... convertFromCamelCase)
Gets an object List.org.slf4j.Logger
getLogger()
Long
getLong(String propertyName)
Gets a long value.Map<String,Object>
getMap()
Returns the propertybag(JSONObject) in a hashMap<T> T
getObject(String propertyName, Class<T> c, boolean... convertFromCamelCase)
Gets an object value.Object
getObjectByPath(List<String> propertyNames)
Gets the value of a property identified by an array of property names that forms the path.String
getString(String propertyName)
Gets a string value.boolean
has(String propertyName)
Checks whether a property exists.String
toJson()
Converts to a JSON string.String
toJson(SerializationFormattingPolicy formattingPolicy)
Converts to a JSON string.<T> T
toObject(Class<T> c)
Converts to an Object (only POJOs and JSONObject are supported).String
toString()
Gets Simple STRING representation of property bag.
-
-
-
Constructor Detail
-
JsonSerializable
protected JsonSerializable()
-
JsonSerializable
protected JsonSerializable(String jsonString)
Constructor.- Parameters:
jsonString
- the json string that represents the JsonSerializable.
-
-
Method Detail
-
getLogger
public org.slf4j.Logger getLogger()
-
getMap
public Map<String,Object> getMap()
Returns the propertybag(JSONObject) in a hashMap- Returns:
- the HashMap.
-
has
public boolean has(String propertyName)
Checks whether a property exists.- Parameters:
propertyName
- the property to look up.- Returns:
- true if the property exists.
-
get
public Object get(String propertyName)
Gets a property value as Object.- Parameters:
propertyName
- the property to get.- Returns:
- the value of the property.
-
getString
public String getString(String propertyName)
Gets a string value.- Parameters:
propertyName
- the property to get.- Returns:
- the string value.
-
getBoolean
public Boolean getBoolean(String propertyName)
Gets a boolean value.- Parameters:
propertyName
- the property to get.- Returns:
- the boolean value.
-
getInt
public Integer getInt(String propertyName)
Gets an integer value.- Parameters:
propertyName
- the property to get.- Returns:
- the boolean value
-
getLong
public Long getLong(String propertyName)
Gets a long value.- Parameters:
propertyName
- the property to get.- Returns:
- the long value
-
getDouble
public Double getDouble(String propertyName)
Gets a double value.- Parameters:
propertyName
- the property to get.- Returns:
- the double value.
-
getObject
public <T> T getObject(String propertyName, Class<T> c, boolean... convertFromCamelCase)
Gets an object value.- Type Parameters:
T
- the type of the object.- Parameters:
propertyName
- the property to get.c
- the class of the object. If c is a POJO class, it must be a member (and not an anonymous or local) and a static one.convertFromCamelCase
- boolean indicating if String should be converted from camel case to upper case separated by underscore, before converting to required class.- Returns:
- the object value.
-
getList
public <T> List<T> getList(String propertyName, Class<T> c, boolean... convertFromCamelCase)
Gets an object List.- Type Parameters:
T
- the type of the objects in the List.- Parameters:
propertyName
- the property to getc
- the class of the object. If c is a POJO class, it must be a member (and not an anonymous or local) and a static one.convertFromCamelCase
- boolean indicating if String should be converted from camel case to upper case separated by underscore, before converting to required class.- Returns:
- the object collection.
-
getCollection
public <T> Collection<T> getCollection(String propertyName, Class<T> c, boolean... convertFromCamelCase)
Gets an object collection.- Type Parameters:
T
- the type of the objects in the collection.- Parameters:
propertyName
- the property to getc
- the class of the object. If c is a POJO class, it must be a member (and not an anonymous or local) and a static one.convertFromCamelCase
- boolean indicating if String should be converted from camel case to upper case separated by underscore, before converting to required class.- Returns:
- the object collection.
-
getObjectByPath
public Object getObjectByPath(List<String> propertyNames)
Gets the value of a property identified by an array of property names that forms the path.- Parameters:
propertyNames
- that form the path to the property to get.- Returns:
- the value of the property.
-
toObject
public <T> T toObject(Class<T> c)
Converts to an Object (only POJOs and JSONObject are supported).- Type Parameters:
T
- the type of the object.- Parameters:
c
- the class of the object, either a POJO class or JSONObject. If c is a POJO class, it must be a member (and not an anonymous or local) and a static one.- Returns:
- the POJO.
-
toJson
public String toJson()
Converts to a JSON string.- Returns:
- the JSON string.
-
toJson
public String toJson(SerializationFormattingPolicy formattingPolicy)
Converts to a JSON string.- Parameters:
formattingPolicy
- the formatting policy to be used.- Returns:
- the JSON string.
-
-