Class BitolDocumentFormatter
java.lang.Object
org.odpi.openmetadata.frameworks.integration.bitol.BitolDocumentFormatter
BitolDocumentFormatter converts Bitol documents between their serialized form (YAML or JSON) and the Egeria beans.
The Bitol standards use YAML as their primary encoding but JSON is also valid; since JSON is a subset of YAML, a
single YAML-based reader handles both. Documents written by this class are YAML. The class is stateless and its
methods are thread-safe. Parsing problems are reported as IOException so that callers do not need the Jackson
libraries on their classpath.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TfromJSONFragment(String json, Class<T> beanClass) Read a single Bitol bean from a JSON fragment written by toJSONFragment.static <T> List<T> fromJSONFragmentList(String json, Class<T> beanClass) Read a list of Bitol beans from a JSON fragment written by toJSONFragment.static StringReturn the value of the "kind" property of a document without mapping the whole document to a bean.static com.fasterxml.jackson.databind.ObjectMapperCreate a Jackson ObjectMapper that reads and writes Bitol documents in JSON.static com.fasterxml.jackson.databind.ObjectMapperCreate a Jackson ObjectMapper that reads and writes Bitol documents in YAML.static DataContractparseDataContract(String rawDocument) Parse an Open Data Contract Standard (ODCS) data contract.static DataProductparseDataProduct(String rawDocument) Parse an Open Data Product Standard (ODPS) data product.static BitolDocumentparseDocument(String rawDocument) Parse a Bitol document of either kind.static StringtoJSON(BitolDocument document) Write a Bitol document as JSON.static StringtoJSONFragment(Object bean) Write any Bitol bean (or list of beans) as JSON.static StringtoYAML(BitolDocument document) Write a Bitol document as YAML (the standards' primary encoding).
-
Method Details
-
newYAMLMapper
public static com.fasterxml.jackson.databind.ObjectMapper newYAMLMapper()Create a Jackson ObjectMapper that reads and writes Bitol documents in YAML. It also reads JSON. A new mapper is returned each time so that the caller can configure it further.- Returns:
- configured mapper
-
newJSONMapper
public static com.fasterxml.jackson.databind.ObjectMapper newJSONMapper()Create a Jackson ObjectMapper that reads and writes Bitol documents in JSON. A new mapper is returned each time so that the caller can configure it further.- Returns:
- configured mapper
-
getKind
Return the value of the "kind" property of a document without mapping the whole document to a bean. This is useful for routing a document whose full content cannot be parsed.- Parameters:
rawDocument- document in YAML or JSON format- Returns:
- the kind (typically DataContract or DataProduct) or null if the document has no kind property
- Throws:
IOException- the document is not valid YAML/JSON
-
parseDocument
Parse a Bitol document of either kind. The subclass is selected from the document's "kind" property.- Parameters:
rawDocument- document in YAML or JSON format- Returns:
- DataContract or DataProduct bean
- Throws:
IOException- the document is not valid or has an unrecognized kind
-
parseDataContract
Parse an Open Data Contract Standard (ODCS) data contract.- Parameters:
rawDocument- document in YAML or JSON format- Returns:
- DataContract bean
- Throws:
IOException- the document is not valid or is not a data contract
-
parseDataProduct
Parse an Open Data Product Standard (ODPS) data product.- Parameters:
rawDocument- document in YAML or JSON format- Returns:
- DataProduct bean
- Throws:
IOException- the document is not valid or is not a data product
-
toYAML
Write a Bitol document as YAML (the standards' primary encoding).- Parameters:
document- DataContract or DataProduct bean- Returns:
- YAML string
- Throws:
IOException- problem serializing the bean
-
toJSONFragment
Write any Bitol bean (or list of beans) as JSON. This is used to keep fragments of a document, such as its SLA properties, losslessly in the additional properties of an open metadata element.- Parameters:
bean- bean or list of beans- Returns:
- JSON string
- Throws:
IOException- problem serializing the bean
-
fromJSONFragment
Read a single Bitol bean from a JSON fragment written by toJSONFragment.- Type Parameters:
T- bean type- Parameters:
json- JSON string (may be null)beanClass- class of the bean- Returns:
- bean or null if the fragment is absent
- Throws:
IOException- problem parsing the JSON
-
fromJSONFragmentList
Read a list of Bitol beans from a JSON fragment written by toJSONFragment.- Type Parameters:
T- bean type- Parameters:
json- JSON string (may be null)beanClass- class of the list elements- Returns:
- list of beans or null if the fragment is absent
- Throws:
IOException- problem parsing the JSON
-
toJSON
Write a Bitol document as JSON.- Parameters:
document- DataContract or DataProduct bean- Returns:
- JSON string
- Throws:
IOException- problem serializing the bean
-