com.algolia.model.search.HighlightResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algoliasearch Show documentation
Show all versions of algoliasearch Show documentation
Java client for Algolia Search API
The newest version!
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost
// - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
package com.algolia.model.search;
import com.algolia.exceptions.AlgoliaRuntimeException;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
/** HighlightResult */
@JsonDeserialize(using = HighlightResult.Deserializer.class)
public interface HighlightResult {
// HighlightResult as Map wrapper.
static HighlightResult of(Map value) {
return new MapOfStringHighlightResultWrapper(value);
}
// HighlightResult as List wrapper.
static HighlightResult of(List value) {
return new ListOfHighlightResultWrapper(value);
}
// HighlightResult as Map wrapper.
@JsonSerialize(using = MapOfStringHighlightResultWrapper.Serializer.class)
class MapOfStringHighlightResultWrapper implements HighlightResult {
private final Map value;
MapOfStringHighlightResultWrapper(Map value) {
this.value = value;
}
public Map getValue() {
return value;
}
static class Serializer extends JsonSerializer {
@Override
public void serialize(MapOfStringHighlightResultWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeObject(value.getValue());
}
}
}
// HighlightResult as List wrapper.
@JsonSerialize(using = ListOfHighlightResultWrapper.Serializer.class)
class ListOfHighlightResultWrapper implements HighlightResult {
private final List value;
ListOfHighlightResultWrapper(List value) {
this.value = value;
}
public List getValue() {
return value;
}
static class Serializer extends JsonSerializer {
@Override
public void serialize(ListOfHighlightResultWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeObject(value.getValue());
}
}
}
class Deserializer extends JsonDeserializer {
private static final Logger LOGGER = Logger.getLogger(Deserializer.class.getName());
@Override
public HighlightResult deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonNode tree = jp.readValueAsTree();
// deserialize HighlightResultOption
if (tree.isObject() && tree.has("matchLevel") && tree.has("matchedWords")) {
try (JsonParser parser = tree.traverse(jp.getCodec())) {
return parser.readValueAs(HighlightResultOption.class);
} catch (Exception e) {
// deserialization failed, continue
LOGGER.finest("Failed to deserialize oneOf HighlightResultOption (error: " + e.getMessage() + ") (type: HighlightResultOption)");
}
}
// deserialize Map
if (tree.isObject()) {
try (JsonParser parser = tree.traverse(jp.getCodec())) {
Map value = parser.readValueAs(new TypeReference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy