Package eu.c6.gibraltar.api.common
Class CObject
java.lang.Object
eu.c6.gibraltar.api.common.CObject
- All Implemented Interfaces:
ICObject,Serializable,Cloneable
- Direct Known Subclasses:
AnyFolder,AnyGroup,AnyRoom,AnyTask,AnyTaskAction,AnyTaskAttachment,AnyUser,AnyUsersReporting,ApiColumn,ApiConfigModule,ApiDuplicatesResult,ApiExportConfigOptions,ApiFilteredSearchRequest,ApiFullTextSearchRequest,ApiImportConfigOptions,ApiLabel,ApiMember,ApiMetadataDocument,ApiOcrFileFeedback,ApiOcrResult,ApiSendTaskResult,ApiSignUrlResult,Labels,Predicate,Range,View
The Class CObject to implements ICObject used to manage JSON data.
Example :
ICObject jsonObj = new CObject();
jsonObj.set("myField", "Value 01");
jsonObj.set("my.path.field", "Value 02");
jsonObj.set("myFieldArray", Arrays.asList("A", "B", "C"));
ICObject jsonNestObj = new CObject();
jsonNestObj.set("nestedField", "Nested Value 01");
jsonObj.set("nestedObjField", jsonNestObj);
String myField = jsonObj.getString("myField");
String myPathField = jsonObj.getString("my.path.field");
List<String> myArrayField = jsonObj.getListString("myFieldArray");
ICObject myNestedObj = jsonObj.getNestedObject("nestedObjField");
String nestedObjectField = jsonObj.getNestedObject("nestedObjField").getString("nestedField");
- See Also:
-
Field Summary
Fields inherited from interface eu.c6.gibraltar.api.common.ICObject
CHARSET, FIELD_SEPARATOR_DOT, FIELD_SEPARATOR_PATH -
Constructor Summary
ConstructorsConstructorDescriptionCObject()Instantiates a new CObject.Instantiates a new CObject from another instance of ICObject.CObject(InputStream input) Instantiates a new CObject from inputsteam of JSON.Instantiates a new CObject from reader of JSON data.Instantiates a new CObject from valid JSON string.Instantiates a new CObject with a field already set.Instantiates a new CObject from map of key/values. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddIntoList(String fieldOrPath, Collection<?> values) Append values into a field with a list of values.voidaddValueIntoList(String fieldOrPath, Object value) Append value into a field with a list of values.static StringAppend all the provided parameters to build a path separated by the default path separator.voidClear list values.clone()Clone the object.<T extends ICObject>
TClone the object as new class.<T extends ICObject>
TClone the object as new class.booleanChecks if object contains a field with specified value.booleancontainsField(String field) Check if object contains a field.static StringConvert field name path using '.' to JSON path using '/'static StringConvert JSON path using '/' to field name path using '.'booleanChecks if current object is equals to another.Gets the object value.booleangetBoolean(String field) Gets the boolean value.booleangetBoolean(String field, boolean defaultValue) Gets the boolean value.Gets the date value or NULL if field does not exsit.Gets the date value.doubleGets the double value or 0 if field does not exist.doubleGets the double value.Gets the direct field names as iterator.Gets the field names flatten list of all fields recursively.Gets the field names list.getInputStream(boolean prettyPrint) Gets the object as input stream.intGets the integer value.intGets the integer value.Gets the list of object from a field with list of values.getListNestedObject(String fieldOrPath) Gets the list of nested objects.<T> List<T>getListNestedObject(String fieldOrPath, Class<T> clazz) This method returns a list of values instanciated as the Class passed as parameters.<T> List<T>getListNestedObject(String fieldOrPath, Class<T> clazz, Class<? extends T> implClazz) Returns a list of values instantiated as the Class passed as parameters and implementation class passed as argument.getListNestedObjectByAttribute(String field, String attributeName, String attributeValue) Gets the list nested object filtered by nested object field value.<T> List<T>getListNestedObjectByAttribute(String field, String attributeName, String attributeValue, Class<T> clazz) Gets the list nested object instantiated with a class and filtered by nested object field value.intgetListSize(String fieldOrPath) Gets the list size of a field with a list of values..getListString(String fieldOrPath) Gets the list of string.getLocalDateTime(String field) Gets the local date time value or NULL if field does not exist.getLocalDateTime(String field, LocalDateTime defaultValue) Gets the local date time value.longGets the long value or 0 if field does not exist.longGets the long value.getNestedObject(String field) Gets the nested object.<T extends ICObject>
TgetNestedObject(String fieldOrPath, Class<T> clazz) Gets the nested object instantiated with a provided class.<T extends ICObject>
TgetNestedObject(String fieldOrPath, Class<T> clazz, Class<? extends T> implClazz) Gets the nested object instantiated with a provided class.Gets the nested object field names list.getOutputStream(boolean prettyPrint) Gets the object as output stream.getReader(boolean prettyPrint) Gets the object as reader.Gets the string value or NULL if field does not exist.Gets the string value.voidinsertIntoList(String fieldOrPath, Object value, int i) Insert a value into a field with a list of values at the specified index.booleanChecks if a field is a boolean.booleanChecks if the field is a date.booleanisDateList(String field) Checks if the field is list of dates.booleanChecks if the field is a double.booleanisEmpty()Gets the array nodes.booleanisFieldEmpty(String fieldOrPath) Checks if the field is empty.booleanChecks if the field is an integer.static booleanisJSONValid(String jSonString) Checks if is a JSON is valid and can be parsed by CObject.booleanChecks if the field is a list.booleanisNestedObject(String fieldOrPath) Checks if the field is a nested object.booleanisNestedObjectList(String field) Checks if the field is a list of nested objectsbooleanChecks if the field is a string.Load object from another instance of ICObject.load(InputStream input) Load object from input JSON stream.voidMerge another instance of ICObject into this object.Merge deeply another instance of ICObject into this object.Compared to merge(), this method merges every values and is not limited to tree nodes.static ICObjectCreates a CObject from parsed JSON stringvoidRemoves the field.voidremoveFromList(String fieldOrPath, Collection<?> values) Removes values from list values of a field.voidremoveValueFromList(String fieldOrPath, Object toBeRemovedValue) Removes the value from list values of a field.voidreplaceIntoList(String fieldOrPath, Object value, int i) Replaces a value into a field with a list of values using index.voidresetField(String field) Reset a field.voidSets the field typed value.voidSets the double value.voidSets the long value.voidSets the field typed value.voidSets the field typed value.voidSets the string value.voidset(String field, LocalDateTime value) Sets the local date time value.voidSets the date value.voidSets the field value with a new nested object created from a Map.voidsetList(String field, Collection<?> values) Sets the list values.voidSets the null value.Convert to text value.Get map of flatten names with values.toJson()Convert object to a JSON string formated.toMap()Convert object to a map.toString()Convert object to a string.toString(boolean autoIndent) Convert to string with auto indentation.
-
Constructor Details
-
CObject
public CObject()Instantiates a new CObject. -
CObject
Instantiates a new CObject from another instance of ICObject.- Parameters:
otherObj- the other IObject instance
-
CObject
Instantiates a new CObject from valid JSON string.- Parameters:
jSonString- the JSON string
-
CObject
Instantiates a new CObject from map of key/values. All map keys are converted to field name.- Parameters:
jSonMap- the Map of key/values
-
CObject
Instantiates a new CObject with a field already set.- Parameters:
fieldName- the field name to setvalue- the value
-
CObject
Instantiates a new CObject from inputsteam of JSON.- Parameters:
input- the input stream
-
CObject
Instantiates a new CObject from reader of JSON data.- Parameters:
reader- the reader
-
-
Method Details
-
isJSONValid
Checks if is a JSON is valid and can be parsed by CObject.- Parameters:
jSonString- the JSON string- Returns:
- true, if JSON is valid
-
convertJsonPathToFieldName
Convert JSON path using '/' to field name path using '.'- Parameters:
path- the path- Returns:
- the converted path
-
convertFieldNameToJsonPath
Convert field name path using '.' to JSON path using '/'- Parameters:
path- the path- Returns:
- the converted path
-
buildPath
Append all the provided parameters to build a path separated by the default path separator.- Parameters:
paths- a list of object that'll be used to create the path- Returns:
- the builded path as string
-
parse
Creates a CObject from parsed JSON string- Parameters:
jSonString- the JSON string- Returns:
- the new ICObject instance
-
load
Description copied from interface:ICObjectLoad object from another instance of ICObject. -
load
Description copied from interface:ICObjectLoad object from input JSON stream.- Specified by:
loadin interfaceICObject- Parameters:
input- the input stream. Must contain JSON string.- Returns:
- the object loaded
- Throws:
IOException- I/O exception has occurred or stream cannot be parsed.
-
merge
Description copied from interface:ICObjectMerge another instance of ICObject into this object. The merge adds missing fields and overwrite existings ones. -
mergeDeep
Description copied from interface:ICObjectMerge deeply another instance of ICObject into this object.Compared to merge(), this method merges every values and is not limited to tree nodes. Use it if you want to merge everything including leaves- Specified by:
mergeDeepin interfaceICObject- Parameters:
json- Object instance of ICObject to mergekeepExisting- : if set to true, any value existing in the source object won't be overriden by the json provided in parameterskipEmpty- : if set to true, any incoming value with empty string ("") will be considered as null and will not override the source value- Returns:
- the object merged
-
isEmpty
public boolean isEmpty()Gets the array nodes. -
getFieldNames
Description copied from interface:ICObjectGets the direct field names as iterator.- Specified by:
getFieldNamesin interfaceICObject- Returns:
- the field names iterator
-
getFieldNamesList
Description copied from interface:ICObjectGets the field names list.- Specified by:
getFieldNamesListin interfaceICObject- Returns:
- the field names list
-
getNestedObjectNamesList
Description copied from interface:ICObjectGets the nested object field names list.- Specified by:
getNestedObjectNamesListin interfaceICObject- Returns:
- the list of field names containing a nested object
-
getFieldNamesFlattenList
Description copied from interface:ICObjectGets the field names flatten list of all fields recursively. Indirect filed names use the dot path pattern (a.b.c)- Specified by:
getFieldNamesFlattenListin interfaceICObject- Returns:
- the field names flatten list
-
containsField
Description copied from interface:ICObjectCheck if object contains a field.- Specified by:
containsFieldin interfaceICObject- Parameters:
field- the field name or field path to search- Returns:
- true, if the field exists
-
getBoolean
Description copied from interface:ICObjectGets the boolean value.- Specified by:
getBooleanin interfaceICObject- Parameters:
field- the field name or field pathdefaultValue- the default value if field does not exist- Returns:
- the boolean value
-
getBoolean
Description copied from interface:ICObjectGets the boolean value.- Specified by:
getBooleanin interfaceICObject- Parameters:
field- the field name or field path- Returns:
- the boolean value or false if field does not exist
-
getNestedObject
Description copied from interface:ICObjectGets the nested object instantiated with a provided class.- Specified by:
getNestedObjectin interfaceICObject- Type Parameters:
T- the generic type- Parameters:
fieldOrPath- the field name or field pathclazz- the implementation or interface class- Returns:
- the nested object
-
getNestedObject
public <T extends ICObject> T getNestedObject(String fieldOrPath, Class<T> clazz, Class<? extends T> implClazz) Description copied from interface:ICObjectGets the nested object instantiated with a provided class.- Specified by:
getNestedObjectin interfaceICObject- Type Parameters:
T- the generic type- Parameters:
fieldOrPath- the field name or field pathclazz- the class interfaceimplClazz- the implementation class- Returns:
- the nested object
-
getNestedObject
Description copied from interface:ICObjectGets the nested object.- Specified by:
getNestedObjectin interfaceICObject- Parameters:
field- the field name or field path- Returns:
- the nested object
-
getList
Description copied from interface:ICObjectGets the list of object from a field with list of values. -
get
Description copied from interface:ICObjectGets the object value. -
getDate
Description copied from interface:ICObjectGets the date value. -
getDate
Description copied from interface:ICObjectGets the date value or NULL if field does not exsit. -
getLocalDateTime
Description copied from interface:ICObjectGets the local date time value or NULL if field does not exist.- Specified by:
getLocalDateTimein interfaceICObject- Parameters:
field- the field name or field path- Returns:
- the local date time value or NULL
-
getLocalDateTime
Description copied from interface:ICObjectGets the local date time value.- Specified by:
getLocalDateTimein interfaceICObject- Parameters:
field- the field name or field pathdefaultValue- the default value if field does not exist- Returns:
- the local date time
-
getInt
Description copied from interface:ICObjectGets the integer value. -
getInt
Description copied from interface:ICObjectGets the integer value. -
getLong
Description copied from interface:ICObjectGets the long value. -
getLong
Description copied from interface:ICObjectGets the long value or 0 if field does not exist. -
getDouble
Description copied from interface:ICObjectGets the double value. -
getDouble
Description copied from interface:ICObjectGets the double value or 0 if field does not exist. -
getString
Description copied from interface:ICObjectGets the string value. -
isFieldEmpty
Description copied from interface:ICObjectChecks if the field is empty.- Specified by:
isFieldEmptyin interfaceICObject- Parameters:
fieldOrPath- the field name or field path- Returns:
- true, if the field is empty string or empty list.
-
getString
Description copied from interface:ICObjectGets the string value or NULL if field does not exist. -
remove
Description copied from interface:ICObjectRemoves the field. -
resetField
Description copied from interface:ICObjectReset a field.- Specified by:
resetFieldin interfaceICObject- Parameters:
field- the field
-
toMap
Description copied from interface:ICObjectConvert object to a map. -
toFlattenMapValues
Description copied from interface:ICObjectGet map of flatten names with values. Map only include final values and list values but intermediate nested object.ex : {a : "a", b : { c : "c", d : ["d1",d2",d3"]} return a map {a = "a", b.c = "c", b.d= ["d1",d2",d3"]}
Separator used for field names is the dot.
- Specified by:
toFlattenMapValuesin interfaceICObject- Returns:
- Map of values
-
toJson
Description copied from interface:ICObjectConvert object to a JSON string formated. -
toString
Description copied from interface:ICObjectConvert to string with auto indentation. -
toString
Description copied from interface:ICObjectConvert object to a string. -
set
Description copied from interface:ICObjectSets the field typed value. -
set
Description copied from interface:ICObjectSets the long value. -
set
Description copied from interface:ICObjectSets the double value. -
set
Description copied from interface:ICObjectSets the string value. -
set
Description copied from interface:ICObjectSets the date value. -
set
Description copied from interface:ICObjectSets the local date time value. -
setList
Description copied from interface:ICObjectSets the list values. -
clearList
Description copied from interface:ICObjectClear list values. -
isList
Description copied from interface:ICObjectChecks if the field is a list. -
isBoolean
Description copied from interface:ICObjectChecks if a field is a boolean. -
isString
Description copied from interface:ICObjectChecks if the field is a string. -
isInt
Description copied from interface:ICObjectChecks if the field is an integer. -
isDouble
Description copied from interface:ICObjectChecks if the field is a double. -
isDateList
Description copied from interface:ICObjectChecks if the field is list of dates.- Specified by:
isDateListin interfaceICObject- Parameters:
field- the field- Returns:
- true, if the field is date list
-
isDate
Description copied from interface:ICObjectChecks if the field is a date. -
isNestedObject
Description copied from interface:ICObjectChecks if the field is a nested object.- Specified by:
isNestedObjectin interfaceICObject- Parameters:
fieldOrPath- the field name or field path- Returns:
- true, if the field is a nested object
-
isNestedObjectList
Description copied from interface:ICObjectChecks if the field is a list of nested objects- Specified by:
isNestedObjectListin interfaceICObject- Parameters:
field- the field- Returns:
- true, if the field is nested object list
-
getListString
Description copied from interface:ICObjectGets the list of string.- Specified by:
getListStringin interfaceICObject- Parameters:
fieldOrPath- the field name or field path- Returns:
- the list string or empty list string if field does not exist
-
getListNestedObject
This method returns a list of values instanciated as the Class passed as parameters.!! WARNING : Be sure that the class you are passing as parameter (or its implementation) has a constructor with the JsonNode parameters or it will not work.
- Specified by:
getListNestedObjectin interfaceICObject- Type Parameters:
T- the generic type- Parameters:
fieldOrPath- : name of the field used to retrieve the list.clazz- : class used to instantiate the object returned in the list.- Returns:
- a String containing the response
-
getListNestedObject
public <T> List<T> getListNestedObject(String fieldOrPath, Class<T> clazz, Class<? extends T> implClazz) Description copied from interface:ICObjectReturns a list of values instantiated as the Class passed as parameters and implementation class passed as argument.Be sure that the class you are passing as parameter (or its implementation) has a constructor with the JsonNode parameters or it will not work.
- Specified by:
getListNestedObjectin interfaceICObject- Type Parameters:
T- the generic type implemeting JsonNode or CObject *- Parameters:
fieldOrPath- name of the field used to retrieve the list.clazz- class used to instantiate the object returned in the list.implClazz- class used to instaciante the object if Clazz corresponds to an interface- Returns:
- a List of instantiated object
-
getListNestedObject
Description copied from interface:ICObjectGets the list of nested objects.- Specified by:
getListNestedObjectin interfaceICObject- Parameters:
fieldOrPath- the field name or field path- Returns:
- the list nested objects or empty list if field does not exist
-
getListNestedObjectByAttribute
public List<ICObject> getListNestedObjectByAttribute(String field, String attributeName, String attributeValue) Description copied from interface:ICObjectGets the list nested object filtered by nested object field value.- Specified by:
getListNestedObjectByAttributein interfaceICObject- Parameters:
field- name of the field used to retrieve the listattributeName- the field name to test on nested objectsattributeValue- the field value to test (object.equals())- Returns:
- the filtered list of nested object matching field value
-
getListNestedObjectByAttribute
public <T> List<T> getListNestedObjectByAttribute(String field, String attributeName, String attributeValue, Class<T> clazz) Description copied from interface:ICObjectGets the list nested object instantiated with a class and filtered by nested object field value.- Specified by:
getListNestedObjectByAttributein interfaceICObject- Type Parameters:
T- the generic type implemeting JsonNode or CObject- Parameters:
field- name of the field used to retrieve the listattributeName- the field name to test on nested objectsattributeValue- the field value to test (object.equals())clazz- class used to instantiate the object returned in the list.- Returns:
- the filtered list of nested object matching field value
-
set
Description copied from interface:ICObjectSets the field typed value. -
set
Description copied from interface:ICObjectSets the field value with a new nested object created from a Map. Each key/object from the map is converted to a field/field value in the new object. -
set
Description copied from interface:ICObjectSets the field typed value. -
setNull
Description copied from interface:ICObjectSets the null value. -
addValueIntoList
Description copied from interface:ICObjectAppend value into a field with a list of values.- Specified by:
addValueIntoListin interfaceICObject- Parameters:
fieldOrPath- the field name or field pathvalue- the value
-
addIntoList
Description copied from interface:ICObjectAppend values into a field with a list of values.- Specified by:
addIntoListin interfaceICObject- Parameters:
fieldOrPath- the field name or field pathvalues- the values
-
getListSize
Description copied from interface:ICObjectGets the list size of a field with a list of values..- Specified by:
getListSizein interfaceICObject- Parameters:
fieldOrPath- the field name or field path- Returns:
- the list size or 0 if field is not a list
-
insertIntoList
Description copied from interface:ICObjectInsert a value into a field with a list of values at the specified index.- Specified by:
insertIntoListin interfaceICObject- Parameters:
fieldOrPath- the field name or field pathvalue- the valuei- the index
-
replaceIntoList
Description copied from interface:ICObjectReplaces a value into a field with a list of values using index.- Specified by:
replaceIntoListin interfaceICObject- Parameters:
fieldOrPath- the field name or field pathvalue- the value to seti- the index to replace into the list of values
-
removeValueFromList
Description copied from interface:ICObjectRemoves the value from list values of a field.- Specified by:
removeValueFromListin interfaceICObject- Parameters:
fieldOrPath- the field name or field pathtoBeRemovedValue- the value to be removed
-
removeFromList
Description copied from interface:ICObjectRemoves values from list values of a field.- Specified by:
removeFromListin interfaceICObject- Parameters:
fieldOrPath- the field name or field pathvalues- the values to remove
-
contains
Description copied from interface:ICObjectChecks if object contains a field with specified value. -
equals
Description copied from interface:ICObjectChecks if current object is equals to another. -
getInputStream
Description copied from interface:ICObjectGets the object as input stream.- Specified by:
getInputStreamin interfaceICObject- Parameters:
prettyPrint- Set to true for pretty print- Returns:
- the input stream
-
getReader
Description copied from interface:ICObjectGets the object as reader.- Specified by:
getReaderin interfaceICObject- Parameters:
prettyPrint- tSet to true for pretty print- Returns:
- the reader
- Throws:
UnsupportedEncodingException- the unsupported encoding exception
-
getOutputStream
Description copied from interface:ICObjectGets the object as output stream.- Specified by:
getOutputStreamin interfaceICObject- Parameters:
prettyPrint- Set to true for pretty print- Returns:
- the output stream
-
clone
Description copied from interface:ICObjectClone the object. -
clone
Description copied from interface:ICObjectClone the object as new class. -
clone
Description copied from interface:ICObjectClone the object as new class. -
textValue
Description copied from interface:ICObjectConvert to text value.
-