Class OpenLineageClientUtils

java.lang.Object
io.openlineage.client.OpenLineageClientUtils

public final class OpenLineageClientUtils extends Object
Utility class for OpenLineageClient that provides common functionalities for object mapping, JSON and YAML parsing, and URI manipulation.
  • Method Details

    • newObjectMapper

      public static com.fasterxml.jackson.databind.ObjectMapper newObjectMapper()
      Creates a new ObjectMapper 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 new ObjectMapper 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

      public static void configureObjectMapper(String... disableFacets)
      Configures the object mapper to exclude specified facets from being serialized.
      Parameters:
      disableFacets - Array of facet names to be excluded from serialization.
    • toJson

      public static String toJson(@NonNull @NonNull Object value) throws UncheckedIOException
      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 a OpenLineage.RunEvent instance.
      Parameters:
      json - The JSON string representing a OpenLineage.RunEvent.
      Returns:
      An instance of OpenLineage.RunEvent.
      Throws:
      UncheckedIOException - If an I/O error occurs during conversion.
    • convertValue

      public static <T> T convertValue(Object fromValue, Class<T> toValueType)
      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

      public 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.
      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

      public static URI toUri(@NonNull @NonNull String urlString) throws OpenLineageClientException
      Converts a string URL into an URI 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 an OpenLineageClientException if one of the following conditions are met:
      1. The provided configPathProvider is null
      2. No configuration file could be found at any of the provided paths
      3. 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 an InputStream.
      Type Parameters:
      T - generic type of merged config
      Parameters:
      inputStream - The InputStream 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 an InputStream.
      Type Parameters:
      T - generic type of merged config
      Parameters:
      inputStream - The InputStream 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.