Package com.nuix.superutilities.export
Class JsonExporter
- java.lang.Object
-
- com.nuix.superutilities.export.JsonExporter
-
public class JsonExporter extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
binaryCategory
protected static java.lang.String
booleanCategory
protected static java.lang.String
dateTimeCategory
protected static java.lang.String
durationCategory
protected static java.util.Map<java.lang.String,java.lang.Integer>
encounteredPropertyNameCounts
protected static java.lang.String
floatCategory
protected static java.lang.String
integerCategory
protected static java.util.Map<nuix.ItemType,java.util.Map<java.lang.String,java.lang.String>>
itemTypeMapCache
protected static java.lang.String
longCategory
protected static java.lang.String
otherCategory
protected static java.lang.String
stringCategory
-
Constructor Summary
Constructors Constructor Description JsonExporter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beforeSerialization(java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> callback)
Allows you to provide a callback which can inspect or modify the nested series of Maps before they are serialized by GSON to JSON byexportItemAsJson(Item, File)
orconvertItemToJsonString(Item)
.java.lang.String
convertItemToJsonString(nuix.Item item)
Converts an item to a JSON String representation.java.lang.String
convertSourceItemToJsonString(nuix.SourceItem sourceItem)
Converts a SourceItem to a JSON String representation.java.lang.String
convertWorkerItemToJsonString(nuix.WorkerItem workerItem)
Converts a WorkerItem to a JSON String representation.void
exportItemAsJson(nuix.Item item, java.io.File exportFilePath)
Exports an item as a JSON representation.void
exportSourceItemAsJson(nuix.SourceItem sourceItem, java.io.File exportFilePath)
Exports an source item as a JSON representation.void
exportWorkerItemAsJson(nuix.WorkerItem workerItem, java.io.File exportFilePath)
Exports a worker item as a JSON representation.boolean
getIncludeChildGuids()
Gets whether child GUIDs should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.boolean
getIncludeCustomMetadata()
Gets whether item custom metadata will be included in generated JSONboolean
getIncludeParentGuid()
Gets whether parent GUID should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.boolean
getIncludePathGuids()
Gets whether path GUIDs should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.boolean
getIncludeProperties()
Gets whether item metadata properties will be included in generated JSONboolean
getIncludeTags()
Gets whether items' tags will be included in generated JSONboolean
getIncludeText()
Gets whether item content text will be included in generated JSONboolean
getPrettyPrint()
Gets whether JSON will be "pretty printed".boolean
getSerializeNulls()
Gets whether entries with a null value are included in the generated JSONstatic java.util.Map<java.lang.String,java.lang.Object>
mapAddress(nuix.Address address)
Converts a Nuix Address object to a HashMap<String,Object> for JSON serialization.static java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
mapAddresses(java.util.List<nuix.Address> addresses)
Converts a List of Nuix Address objects to a list of HashMap<String,Object> for JSON serialization.static java.util.Map<java.lang.String,java.lang.Object>
mapCommunication(nuix.Communication comm)
Converts a Nuix Communication object to a HashMap<String,Object> for JSON serialization.java.util.Map<java.lang.String,java.lang.Object>
mapItem(nuix.Item item)
Converts a Nuix item into a series of nested Map objects, which later can be easily serialized into JSON.static java.util.Map<java.lang.String,java.lang.String>
mapItemType(nuix.ItemType itemType)
Converts a Nuix ItemType object to a HashMap<String,String> for JSON serialization.static java.util.Map<java.lang.String,java.lang.Object>
mapProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
This method generates aMap
of the properties for an item, organizing properties into sub-categories based on the data type of their values.java.util.Map<java.lang.String,java.lang.Object>
mapSourceItem(nuix.SourceItem sourceItem)
This method takes a provided SourceItem and generates a series of nestedMap
instances representing the SourceItem and its data.java.util.Map<java.lang.String,java.lang.Object>
mapWorkerItem(nuix.WorkerItem workerItem)
This method take a provided WorkerItem and generates a series of nestedMap
instances representing the WorkerItem and its data.void
setIncludeChildGuids(boolean includeChildGuids)
Sets whether child GUIDs should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.void
setIncludeCustomMetadata(boolean includeCustomMetadata)
Sets whether item custom metadata will be included in generated JSONvoid
setIncludeParentGuid(boolean includeParentGuid)
Sets whether parent GUID should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.void
setIncludePathGuids(boolean includePathGuids)
Sets whether path GUIDs should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.void
setIncludeProperties(boolean includeProperties)
Sets whether item metadata properties will be included in generated JSONvoid
setIncludeTags(boolean includeTags)
Sets whether items' tags will be included in generated JSONvoid
setIncludeText(boolean includeText)
Sets whether item content text will be included in generated JSONvoid
setPrettyPrint(boolean prettyPrint)
Sets whether JSON will be "pretty printed".void
setSerializeNulls(boolean serializeNulls)
Sets whether entries with null value are included in the generated JSON
-
-
-
Field Detail
-
itemTypeMapCache
protected static java.util.Map<nuix.ItemType,java.util.Map<java.lang.String,java.lang.String>> itemTypeMapCache
-
encounteredPropertyNameCounts
protected static java.util.Map<java.lang.String,java.lang.Integer> encounteredPropertyNameCounts
-
booleanCategory
protected static java.lang.String booleanCategory
-
integerCategory
protected static java.lang.String integerCategory
-
longCategory
protected static java.lang.String longCategory
-
floatCategory
protected static java.lang.String floatCategory
-
stringCategory
protected static java.lang.String stringCategory
-
dateTimeCategory
protected static java.lang.String dateTimeCategory
-
durationCategory
protected static java.lang.String durationCategory
-
binaryCategory
protected static java.lang.String binaryCategory
-
otherCategory
protected static java.lang.String otherCategory
-
-
Method Detail
-
beforeSerialization
public void beforeSerialization(java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> callback)
Allows you to provide a callback which can inspect or modify the nested series of Maps before they are serialized by GSON to JSON byexportItemAsJson(Item, File)
orconvertItemToJsonString(Item)
.- Parameters:
callback
- A callback which may inspect or modify the nested Map form of an item before it is serialized to JSON
-
getIncludeText
public boolean getIncludeText()
Gets whether item content text will be included in generated JSON- Returns:
- True if content text will be included
-
setIncludeText
public void setIncludeText(boolean includeText)
Sets whether item content text will be included in generated JSON- Parameters:
includeText
- True if content text should be included
-
getIncludeProperties
public boolean getIncludeProperties()
Gets whether item metadata properties will be included in generated JSON- Returns:
- True if item metadata properties will be included in generated JSON
-
setIncludeProperties
public void setIncludeProperties(boolean includeProperties)
Sets whether item metadata properties will be included in generated JSON- Parameters:
includeProperties
- True if item metadata properties should be included in generated JSON
-
getIncludeCustomMetadata
public boolean getIncludeCustomMetadata()
Gets whether item custom metadata will be included in generated JSON- Returns:
- True if item custom metadata will be included in generated JSON
-
setIncludeCustomMetadata
public void setIncludeCustomMetadata(boolean includeCustomMetadata)
Sets whether item custom metadata will be included in generated JSON- Parameters:
includeCustomMetadata
- True if item custom metadata should be included in JSON
-
getIncludeTags
public boolean getIncludeTags()
Gets whether items' tags will be included in generated JSON- Returns:
- True if items' tags will be included in generated JSON
-
setIncludeTags
public void setIncludeTags(boolean includeTags)
Sets whether items' tags will be included in generated JSON- Parameters:
includeTags
- True if items' tags should be included in generated JSON
-
getIncludeParentGuid
public boolean getIncludeParentGuid()
Gets whether parent GUID should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.- Returns:
- True if parent GUID will be serialized.
-
setIncludeParentGuid
public void setIncludeParentGuid(boolean includeParentGuid)
Sets whether parent GUID should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.- Parameters:
includeParentGuid
- True if parent GUID should be serialized.
-
getIncludeChildGuids
public boolean getIncludeChildGuids()
Gets whether child GUIDs should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.- Returns:
- True if child GUIDs will be serialized
-
setIncludeChildGuids
public void setIncludeChildGuids(boolean includeChildGuids)
Sets whether child GUIDs should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.- Parameters:
includeChildGuids
- True if child GUIDs should be serialized
-
getIncludePathGuids
public boolean getIncludePathGuids()
Gets whether path GUIDs should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.- Returns:
- True if path GUIDs will be serialized
-
setIncludePathGuids
public void setIncludePathGuids(boolean includePathGuids)
Sets whether path GUIDs should be serialized when callingmapItem(Item)
, {exportItemAsJson(Item, File)
or {convertItemToJsonString(Item)
.- Parameters:
includePathGuids
- True if path GUIDs should be serialized
-
getSerializeNulls
public boolean getSerializeNulls()
Gets whether entries with a null value are included in the generated JSON- Returns:
- True if entries with a null value will be included in generated JSON
-
setSerializeNulls
public void setSerializeNulls(boolean serializeNulls)
Sets whether entries with null value are included in the generated JSON- Parameters:
serializeNulls
- True if entries with null value should be included in generated JSON
-
getPrettyPrint
public boolean getPrettyPrint()
Gets whether JSON will be "pretty printed". Makes file more human readable, but can also make the file larger with all the extra white space characters for formatting.- Returns:
- True if JSON will be "pretty printed"
-
setPrettyPrint
public void setPrettyPrint(boolean prettyPrint)
Sets whether JSON will be "pretty printed". Makes file more human readable, but can also make the file larger with all the extra white space characters for formatting.- Parameters:
prettyPrint
- True if the output should be "pretty printed"
-
mapWorkerItem
public java.util.Map<java.lang.String,java.lang.Object> mapWorkerItem(nuix.WorkerItem workerItem)
This method take a provided WorkerItem and generates a series of nestedMap
instances representing the WorkerItem and its data. The resultingMap
is later used as input to GSON for serializing to JSON. Internally this gets the SourceItem for the given WorkerItem and provides that tomapSourceItem(SourceItem)
to build most of the Map. After that it adds a few additional entries based on what is available from the WorkerItem.- Parameters:
workerItem
- WorkerItem to serialize into a map- Returns:
- Map representing the WorkerItem and its SourceItem
-
mapSourceItem
public java.util.Map<java.lang.String,java.lang.Object> mapSourceItem(nuix.SourceItem sourceItem)
This method takes a provided SourceItem and generates a series of nestedMap
instances representing the SourceItem and its data. The resultingMap
is later used as input to GSON for serializing to JSON. In turn the following methods are called by this one:mapItemType(ItemType)
,mapProperties(Map)
,mapCommunication(Communication)
- Parameters:
sourceItem
- Source item to serialize into a Map- Returns:
- Map representation of the source item
-
mapItem
public java.util.Map<java.lang.String,java.lang.Object> mapItem(nuix.Item item)
Converts a Nuix item into a series of nested Map objects, which later can be easily serialized into JSON.- Parameters:
item
- The item to serialize into a Map- Returns:
- Map representation of the item
-
exportItemAsJson
public void exportItemAsJson(nuix.Item item, java.io.File exportFilePath)
Exports an item as a JSON representation. Items information is first converted into a series of Map objects by callingmapItem(Item)
, the result of which is then converted into JSON.- Parameters:
item
- The item to serialize into JSONexportFilePath
- File path to write the JSON result to.
-
exportSourceItemAsJson
public void exportSourceItemAsJson(nuix.SourceItem sourceItem, java.io.File exportFilePath)
Exports an source item as a JSON representation. The SourceItem's information is first converted into a series of Map objects by callingmapSourceItem(SourceItem)
, the result of which is then converted into JSON.- Parameters:
sourceItem
- The SourceItem to serialize into JSONexportFilePath
- File path to write the JSON result to.
-
exportWorkerItemAsJson
public void exportWorkerItemAsJson(nuix.WorkerItem workerItem, java.io.File exportFilePath)
Exports a worker item as a JSON representation. The WorkerItem's information is first converted into a series of Map objects by callingmapWorkerItem(WorkerItem)
, the result of which is then converted into JSON.- Parameters:
workerItem
- The WorkerItem to serialize into JSONexportFilePath
- File path to write the JSON result to.
-
convertItemToJsonString
public java.lang.String convertItemToJsonString(nuix.Item item)
Converts an item to a JSON String representation. The Item's information is first converted into a series of Map objects by callingmapItem(Item)
, result of which is then serialized into a JSON String and returned.- Parameters:
item
- The item to serialize into JSON- Returns:
- A JSON String representation of the given item.
-
convertSourceItemToJsonString
public java.lang.String convertSourceItemToJsonString(nuix.SourceItem sourceItem)
Converts a SourceItem to a JSON String representation. The SourceItem's information is first converted into a series of Map objects by callingmapSourceItem(SourceItem)
, result of which is then serialized into a JSON String and returned.- Parameters:
sourceItem
- The SourceItem to serialize into JSON- Returns:
- A JSON String representation of the given SourceItem.
-
convertWorkerItemToJsonString
public java.lang.String convertWorkerItemToJsonString(nuix.WorkerItem workerItem)
Converts a WorkerItem to a JSON String representation. The WorkerItem's information is first converted into a series of Map objects by callingmapWorkerItem(WorkerItem)
, result of which is then serialized into a JSON String and returned.- Parameters:
workerItem
- The WorkerItem to serialize into JSON- Returns:
- A JSON String representation of the given WorkerItem.
-
mapProperties
public static java.util.Map<java.lang.String,java.lang.Object> mapProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
This method generates aMap
of the properties for an item, organizing properties into sub-categories based on the data type of their values.- Parameters:
properties
- A Nuix item properties map to convert- Returns:
- A nested series of
Map
instances with properties categorized by value data type
-
mapItemType
public static java.util.Map<java.lang.String,java.lang.String> mapItemType(nuix.ItemType itemType)
Converts a Nuix ItemType object to a HashMap<String,String> for JSON serialization. This method first checks a local cache to see if the value has already been converted and returns that if so.- Parameters:
itemType
- The Nuix ItemType object to Map-ify- Returns:
- The resulting Map
-
mapCommunication
public static java.util.Map<java.lang.String,java.lang.Object> mapCommunication(nuix.Communication comm)
Converts a Nuix Communication object to a HashMap<String,Object> for JSON serialization. This method in turn callsmapAddresses(List)
.- Parameters:
comm
- The Nuix Communication object to Map-ify- Returns:
- The resulting Map
-
mapAddress
public static java.util.Map<java.lang.String,java.lang.Object> mapAddress(nuix.Address address)
Converts a Nuix Address object to a HashMap<String,Object> for JSON serialization.- Parameters:
address
- The Nuix Address object to Map-ify- Returns:
- The resulting Map
-
mapAddresses
public static java.util.List<java.util.Map<java.lang.String,java.lang.Object>> mapAddresses(java.util.List<nuix.Address> addresses)
Converts a List of Nuix Address objects to a list of HashMap<String,Object> for JSON serialization. This method callsmapAddress(Address)
for each Address object provided.- Parameters:
addresses
- The list of Nuix Address objects to Mapify- Returns:
- The resulting Map
-
-