Package io.openlineage.client
Class OpenLineageClientUtils
java.lang.Object
io.openlineage.client.OpenLineageClientUtils
Utility class for
OpenLineageClient
that provides common functionalities for object
mapping, JSON and YAML parsing, and URI manipulation.-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
configureObjectMapper
(String... disableFacets) Configures the object mapper to exclude specified facets from being serialized.static <T> T
convertValue
(Object fromValue, Class<T> toValueType) Converts the value of an object from one type to another.static <T> T
Converts the provided JSON string to an instance of the specified type.static <T extends OpenLineageConfig>
TloadOpenLineageConfigJson
(InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) Loads and parses OpenLineage JSON configuration from anInputStream
.static <T extends OpenLineageConfig>
TloadOpenLineageConfigYaml
(ConfigPathProvider configPathProvider, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) Loads and parses OpenLineage configuration from the provided paths.static <T extends OpenLineageConfig>
TloadOpenLineageConfigYaml
(InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) Loads and parses OpenLineage YAML configuration from anInputStream
.static <T,
F> T mergeFacets
(Map<String, F> facetsMap, T facetsContainer, Class<T> klass) Merges the given facets map with an existing facets container, giving precedence to the values in the facets map.static com.fasterxml.jackson.databind.ObjectMapper
Creates a newObjectMapper
instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.static com.fasterxml.jackson.databind.ObjectMapper
newObjectMapper
(com.fasterxml.jackson.core.JsonFactory jsonFactory) Creates a newObjectMapper
instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.static OpenLineage.RunEvent
runEventFromJson
(@NonNull String json) Convenience method to convert a JSON string directly into aOpenLineage.RunEvent
instance.static String
Converts the provided value to a JSON string.static URI
Converts a string URL into anURI
object.
-
Method Details
-
newObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper newObjectMapper()Creates a newObjectMapper
instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.- Returns:
- A configured
ObjectMapper
instance.
-
newObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper newObjectMapper(com.fasterxml.jackson.core.JsonFactory jsonFactory) Creates a newObjectMapper
instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.- Parameters:
jsonFactory
- JsonFactory- Returns:
- A configured
ObjectMapper
instance.
-
configureObjectMapper
Configures the object mapper to exclude specified facets from being serialized.- Parameters:
disableFacets
- Array of facet names to be excluded from serialization.
-
toJson
Converts the provided value to a JSON string.- Parameters:
value
- The object to be converted to JSON.- Returns:
- A JSON string representation of the object.
- Throws:
UncheckedIOException
- If an I/O error occurs during conversion.
-
fromJson
public static <T> T fromJson(@NonNull @NonNull String json, @NonNull @NonNull com.fasterxml.jackson.core.type.TypeReference<T> type) throws UncheckedIOException Converts the provided JSON string to an instance of the specified type.- Type Parameters:
T
- The generic type of the return value.- Parameters:
json
- The JSON string to be converted.type
- The type to convert the JSON string into.- Returns:
- An instance of the specified type.
- Throws:
UncheckedIOException
- If an I/O error occurs during conversion.
-
runEventFromJson
public static OpenLineage.RunEvent runEventFromJson(@NonNull @NonNull String json) throws UncheckedIOException Convenience method to convert a JSON string directly into aOpenLineage.RunEvent
instance.- Parameters:
json
- The JSON string representing aOpenLineage.RunEvent
.- Returns:
- An instance of
OpenLineage.RunEvent
. - Throws:
UncheckedIOException
- If an I/O error occurs during conversion.
-
convertValue
Converts the value of an object from one type to another.- Type Parameters:
T
- The generic type of the target type.- Parameters:
fromValue
- The object whose value is to be converted.toValueType
- The target type for the conversion.- Returns:
- An object of the target type with the value converted from the original object.
-
mergeFacets
Merges the given facets map with an existing facets container, giving precedence to the values in the facets map.- Type Parameters:
T
- The type of the facets container.F
- The type of facets in the map.- Parameters:
facetsMap
- A map containing facets to be merged.facetsContainer
- The existing container of facets.klass
- The class of the facets container.- Returns:
- A new instance of the facets container with merged values.
-
toUri
Converts a string URL into anURI
object.- Parameters:
urlString
- The string URL to be converted.- Returns:
- An
URI
object. - Throws:
OpenLineageClientException
- If the given string does not conform to the URI specification.
-
loadOpenLineageConfigYaml
public static <T extends OpenLineageConfig> T loadOpenLineageConfigYaml(ConfigPathProvider configPathProvider, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) throws OpenLineageClientException Loads and parses OpenLineage configuration from the provided paths. Throws anOpenLineageClientException
if one of the following conditions are met:- The provided configPathProvider is null
- No configuration file could be found at any of the provided paths
- Load the default configuration from the classpath if no file is found
- Type Parameters:
T
- generic type of merged config- Parameters:
configPathProvider
- Provides the paths where the configuration files can be found.valueTypeRef
- The type to convert the JSON string into.- Returns:
- An instance of
OpenLineageConfig
containing the parsed configuration. - Throws:
OpenLineageClientException
- According to the rules defined above.
-
loadOpenLineageConfigYaml
public static <T extends OpenLineageConfig> T loadOpenLineageConfigYaml(InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) throws OpenLineageClientException Loads and parses OpenLineage YAML configuration from anInputStream
.- Type Parameters:
T
- generic type of merged config- Parameters:
inputStream
- TheInputStream
from which to load the configuration.valueTypeRef
- The type to convert the JSON string into.- Returns:
- An instance of
OpenLineageConfig
containing the parsed YAML configuration. - Throws:
OpenLineageClientException
- If an error occurs while reading or parsing the configuration.
-
loadOpenLineageConfigJson
public static <T extends OpenLineageConfig> T loadOpenLineageConfigJson(InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) throws OpenLineageClientException Loads and parses OpenLineage JSON configuration from anInputStream
.- Type Parameters:
T
- generic type of merged config- Parameters:
inputStream
- TheInputStream
from which to load the configuration.valueTypeRef
- The type to convert the JSON string into.- Returns:
- An instance of
OpenLineageConfig
containing the parsed JSON configuration. - Throws:
OpenLineageClientException
- If an error occurs while reading or parsing the configuration.
-