com.algolia.model.recommend.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
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.recommend;
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 of(Map value) {
return new MapOfStringSnippetResultWrapper(value);
}
// SnippetResult as List wrapper.
static SnippetResult of(List value) {
return new ListOfSnippetResultWrapper(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 List wrapper.
@JsonSerialize(using = ListOfSnippetResultWrapper.Serializer.class)
class ListOfSnippetResultWrapper implements SnippetResult {
private final List value;
ListOfSnippetResultWrapper(List value) {
this.value = value;
}
public List getValue() {
return value;
}
static class Serializer extends JsonSerializer {
@Override
public void serialize(ListOfSnippetResultWrapper 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