com.algolia.model.search.SnippetResult 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
// 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;
/** SnippetResult */
@JsonDeserialize(using = SnippetResult.Deserializer.class)
public interface SnippetResult {
// SnippetResult as Map wrapper.
static SnippetResult ofMapOfStringSnippetResult(Map value) {
return new MapOfStringSnippetResultWrapper(value);
}
// SnippetResult as Map wrapper.
static SnippetResult ofMapOfStringSnippetResultOption(Map value) {
return new MapOfStringSnippetResultOptionWrapper(value);
}
// SnippetResult as List wrapper.
static SnippetResult of(List value) {
return new ListOfSnippetResultOptionWrapper(value);
}
// SnippetResult as Map wrapper.
@JsonSerialize(using = MapOfStringSnippetResultWrapper.Serializer.class)
class MapOfStringSnippetResultWrapper implements SnippetResult {
private final Map value;
MapOfStringSnippetResultWrapper(Map value) {
this.value = value;
}
public Map getValue() {
return value;
}
static class Serializer extends JsonSerializer {
@Override
public void serialize(MapOfStringSnippetResultWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeObject(value.getValue());
}
}
}
// SnippetResult as Map wrapper.
@JsonSerialize(using = MapOfStringSnippetResultOptionWrapper.Serializer.class)
class MapOfStringSnippetResultOptionWrapper implements SnippetResult {
private final Map value;
MapOfStringSnippetResultOptionWrapper(Map value) {
this.value = value;
}
public Map getValue() {
return value;
}
static class Serializer extends JsonSerializer {
@Override
public void serialize(MapOfStringSnippetResultOptionWrapper value, JsonGenerator gen, SerializerProvider provider)
throws IOException {
gen.writeObject(value.getValue());
}
}
}
// SnippetResult as List wrapper.
@JsonSerialize(using = ListOfSnippetResultOptionWrapper.Serializer.class)
class ListOfSnippetResultOptionWrapper implements SnippetResult {
private final List value;
ListOfSnippetResultOptionWrapper(List value) {
this.value = value;
}
public List getValue() {
return value;
}
static class Serializer extends JsonSerializer {
@Override
public void serialize(ListOfSnippetResultOptionWrapper 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 SnippetResult deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonNode tree = jp.readValueAsTree();
// deserialize SnippetResultOption
if (tree.isObject() && tree.has("matchLevel")) {
try (JsonParser parser = tree.traverse(jp.getCodec())) {
return parser.readValueAs(SnippetResultOption.class);
} catch (Exception e) {
// deserialization failed, continue
LOGGER.finest("Failed to deserialize oneOf SnippetResultOption (error: " + e.getMessage() + ") (type: SnippetResultOption)");
}
}
// 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