com.algolia.model.search.IgnorePlurals 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.logging.Logger;
/**
* Treat singular, plurals, and other forms of declensions as equivalent. You should only use this
* feature for the languages used in your index.
*/
@JsonDeserialize(using = IgnorePlurals.Deserializer.class)
public interface IgnorePlurals {
// IgnorePlurals as List wrapper.
static IgnorePlurals of(List value) {
return new ListOfSupportedLanguageWrapper(value);
}
// IgnorePlurals as Boolean wrapper.
static IgnorePlurals of(Boolean value) {
return new BooleanWrapper(value);
}
// IgnorePlurals as List wrapper.
@JsonSerialize(using = ListOfSupportedLanguageWrapper.Serializer.class)
class ListOfSupportedLanguageWrapper implements IgnorePlurals {
private final List value;
ListOfSupportedLanguageWrapper(List value) {
this.value = value;
}
public List getValue() {
return value;
}
static class Serializer extends JsonSerializer {
@Override
public void serialize(ListOfSupportedLanguageWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeObject(value.getValue());
}
}
}
// IgnorePlurals as Boolean wrapper.
@JsonSerialize(using = BooleanWrapper.Serializer.class)
class BooleanWrapper implements IgnorePlurals {
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 IgnorePlurals 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 IgnorePlurals.ListOfSupportedLanguageWrapper(value);
} catch (Exception e) {
// deserialization failed, continue
LOGGER.finest(
"Failed to deserialize oneOf List (error: " + e.getMessage() + ") (type: List)"
);
}
}
// deserialize BooleanString
if (tree.isTextual()) {
try (JsonParser parser = tree.traverse(jp.getCodec())) {
return parser.readValueAs(BooleanString.class);
} catch (Exception e) {
// deserialization failed, continue
LOGGER.finest("Failed to deserialize oneOf BooleanString (error: " + e.getMessage() + ") (type: BooleanString)");
}
}
// deserialize Boolean
if (tree.isBoolean()) {
try (JsonParser parser = tree.traverse(jp.getCodec())) {
Boolean value = parser.readValueAs(Boolean.class);
return new IgnorePlurals.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 IgnorePlurals getNullValue(DeserializationContext ctxt) throws JsonMappingException {
throw new JsonMappingException(ctxt.getParser(), "IgnorePlurals cannot be null");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy