
io.polyglotted.eswrapper.indexing.IndexSerializer Maven / Gradle / Ivy
package io.polyglotted.eswrapper.indexing;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import io.polyglotted.pgmodel.search.index.FieldMapping;
import io.polyglotted.pgmodel.search.index.Indexed;
import io.polyglotted.pgmodel.search.index.Script;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import static com.google.common.collect.ImmutableSortedSet.copyOf;
import static com.google.common.collect.Iterables.concat;
import static io.polyglotted.eswrapper.ElasticConstants.ALL_META;
import static io.polyglotted.eswrapper.ElasticConstants.META_META;
import static io.polyglotted.eswrapper.ElasticConstants.PARENT_META;
import static io.polyglotted.eswrapper.ElasticConstants.SOURCE_META;
import static io.polyglotted.pgmodel.search.index.FieldType.OBJECT;
import static io.polyglotted.pgmodel.search.index.FieldType.STRING;
import static io.polyglotted.pgmodel.search.index.HiddenFields.hiddenFields;
import static io.polyglotted.pgmodel.search.index.Indexed.NOT_ANALYZED;
public abstract class IndexSerializer {
public static final Gson GSON = new GsonBuilder().disableHtmlEscaping()
.registerTypeAdapter(TypeMapping.class, new TypeMappingSerializer())
.registerTypeAdapter(FieldMapping.class, new FieldMappingSerializer())
.registerTypeAdapter(Script.class, new ScriptMappingSerializer())
.create();
public static final Type LIST_TYPE = new TypeToken>>() {}.getType();
@SuppressWarnings("unchecked")
public static Map deserMap(String json) {
return GSON.fromJson(json, Map.class);
}
@SuppressWarnings("unchecked")
public static List