public class JsonSerializable extends Object implements Serializable
Modifier | Constructor and Description |
---|---|
protected |
JsonSerializable() |
protected |
JsonSerializable(org.json.JSONObject jsonObject)
Constructor.
|
protected |
JsonSerializable(String jsonString)
Constructor.
|
protected |
JsonSerializable(String jsonString,
com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Object |
get(String propertyName)
Gets a property value as Object.
|
Boolean |
getBoolean(String propertyName)
Gets a boolean value.
|
Collection<org.json.JSONObject> |
getCollection(String propertyName)
Gets a JSONObject collection.
|
<T> Collection<T> |
getCollection(String propertyName,
Class<T> c)
Gets an object collection.
|
Double |
getDouble(String propertyName)
Gets a double value.
|
HashMap<String,Object> |
getHashMap()
Returns the propertybag(JSONObject) in a hashMap
|
Integer |
getInt(String propertyName)
Gets an integer value.
|
protected org.slf4j.Logger |
getLogger() |
Long |
getLong(String propertyName)
Gets a long value.
|
protected com.fasterxml.jackson.databind.ObjectMapper |
getMapper() |
org.json.JSONObject |
getObject(String propertyName)
Gets a JSONObject.
|
<T> T |
getObject(String propertyName,
Class<T> c)
Gets an object value.
|
Object |
getObjectByPath(Collection<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.
|
void |
remove(String propertyName)
Removes a value by propertyName.
|
<T> void |
set(String propertyName,
T value)
Sets the value of a property.
|
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.
|
protected JsonSerializable()
protected JsonSerializable(String jsonString, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
jsonString
- the json string that represents the JsonSerializable.objectMapper
- the custom object mapperprotected JsonSerializable(String jsonString)
jsonString
- the json string that represents the JsonSerializable.protected JsonSerializable(org.json.JSONObject jsonObject)
jsonObject
- the json object that represents the JsonSerializable.protected com.fasterxml.jackson.databind.ObjectMapper getMapper()
protected org.slf4j.Logger getLogger()
public HashMap<String,Object> getHashMap()
public boolean has(String propertyName)
propertyName
- the property to look up.public void remove(String propertyName)
propertyName
- the property to remove.public <T> void set(String propertyName, T value)
T
- the type of the object.propertyName
- the property to set.value
- the value of the property.public Object get(String propertyName)
propertyName
- the property to get.public String getString(String propertyName)
propertyName
- the property to get.public Boolean getBoolean(String propertyName)
propertyName
- the property to get.public Integer getInt(String propertyName)
propertyName
- the property to get.public Long getLong(String propertyName)
propertyName
- the property to get.public Double getDouble(String propertyName)
propertyName
- the property to get.public <T> T getObject(String propertyName, Class<T> c)
T
- the type of the object.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.public <T> Collection<T> getCollection(String propertyName, Class<T> c)
T
- the type of the objects in the collection.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.public org.json.JSONObject getObject(String propertyName)
propertyName
- the property to get.public Collection<org.json.JSONObject> getCollection(String propertyName)
propertyName
- the property to get.public Object getObjectByPath(Collection<String> propertyNames)
propertyNames
- that form the path to the the property to get.public <T> T toObject(Class<T> c)
T
- the type of the object.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.public String toJson()
public String toJson(SerializationFormattingPolicy formattingPolicy)
formattingPolicy
- the formatting policy to be used.Copyright © 2018. All rights reserved.