All Downloads are FREE. Search and download functionalities are using the official Maven repository.

zipkin2.elasticsearch.BodyConverters Maven / Gradle / Ivy

The newest version!
/*
 * Copyright The OpenZipkin Authors
 * SPDX-License-Identifier: Apache-2.0
 */
package zipkin2.elasticsearch;

import com.fasterxml.jackson.core.JsonParser;
import java.io.IOException;
import java.util.List;
import java.util.function.Supplier;
import zipkin2.DependencyLink;
import zipkin2.Span;
import zipkin2.elasticsearch.internal.JsonSerializers;
import zipkin2.elasticsearch.internal.client.HttpCall.BodyConverter;
import zipkin2.elasticsearch.internal.client.SearchResultConverter;
import zipkin2.internal.DependencyLinker;

import static zipkin2.elasticsearch.internal.JsonReaders.collectValuesNamed;

final class BodyConverters {
  static final BodyConverter NULL = (parser, contentString) -> null;
  static final BodyConverter> KEYS =
    (parser, contentString) -> collectValuesNamed(parser, "key");
  static final BodyConverter> SPANS =
    SearchResultConverter.create(JsonSerializers.SPAN_PARSER);
  static final BodyConverter> DEPENDENCY_LINKS =
    new SearchResultConverter(JsonSerializers.DEPENDENCY_LINK_PARSER) {
      @Override
      public List convert(JsonParser parser, Supplier contentString)
        throws IOException {
        List result = super.convert(parser, contentString);
        return result.isEmpty() ? result : DependencyLinker.merge(result);
      }
    };
}