com.algolia.model.querysuggestions.Languages Maven / Gradle / Ivy
// 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.querysuggestions;
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.logging.Logger;
/**
* Languages for deduplicating singular and plural suggestions. If specified, only the more popular
* form is included.
*/
@JsonDeserialize(using = Languages.Deserializer.class)
public interface Languages {
// Languages as List wrapper.
static Languages of(List value) {
return new ListOfStringWrapper(value);
}
// Languages as Boolean wrapper.
static Languages of(Boolean value) {
return new BooleanWrapper(value);
}
// Languages as List wrapper.
@JsonSerialize(using = ListOfStringWrapper.Serializer.class)
class ListOfStringWrapper implements Languages {
private final List value;
ListOfStringWrapper(List value) {
this.value = value;
}
public List getValue() {
return value;
}
static class Serializer extends JsonSerializer {
@Override
public void serialize(ListOfStringWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeObject(value.getValue());
}
}
}
// Languages as Boolean wrapper.
@JsonSerialize(using = BooleanWrapper.Serializer.class)
class BooleanWrapper implements Languages {
private final Boolean value;
BooleanWrapper(Boolean value) {
this.value = value;
}
public Boolean getValue() {
return value;
}
static class Serializer extends JsonSerializer {
@Override
public void serialize(BooleanWrapper 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 Languages deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonNode tree = jp.readValueAsTree();
// deserialize List
if (tree.isArray()) {
try (JsonParser parser = tree.traverse(jp.getCodec())) {
List value = parser.readValueAs(new TypeReference>() {});
return new Languages.ListOfStringWrapper(value);
} catch (Exception e) {
// deserialization failed, continue
LOGGER.finest("Failed to deserialize oneOf List (error: " + e.getMessage() + ") (type: List)");
}
}
// deserialize Boolean
if (tree.isBoolean()) {
try (JsonParser parser = tree.traverse(jp.getCodec())) {
Boolean value = parser.readValueAs(Boolean.class);
return new Languages.BooleanWrapper(value);
} catch (Exception e) {
// deserialization failed, continue
LOGGER.finest("Failed to deserialize oneOf Boolean (error: " + e.getMessage() + ") (type: Boolean)");
}
}
throw new AlgoliaRuntimeException(String.format("Failed to deserialize json element: %s", tree));
}
/** Handle deserialization of the 'null' value. */
@Override
public Languages getNullValue(DeserializationContext ctxt) throws JsonMappingException {
throw new JsonMappingException(ctxt.getParser(), "Languages cannot be null");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy