com.basistech.rosette.dm.jackson.MorphoAnalysisListDeserializer Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2023 Basis Technology Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.basistech.rosette.dm.jackson;
import com.basistech.rosette.dm.ArabicMorphoAnalysis;
import com.basistech.rosette.dm.HanMorphoAnalysis;
import com.basistech.rosette.dm.KoreanMorphoAnalysis;
import com.basistech.rosette.dm.MorphoAnalysis;
import com.basistech.rosette.dm.Token;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Jackson deserialization that handles polymorphism of MorphoAnalysis without writing
* out the type in each one.
*/
public final class MorphoAnalysisListDeserializer extends JsonDeserializer> implements ContextualDeserializer {
private static final Set ARABIC_FIELDS;
static {
ImmutableSet.Builder builder = new ImmutableSet.Builder<>();
for (Field field : ArabicMorphoAnalysis.class.getDeclaredFields()) {
try {
MorphoAnalysis.class.getDeclaredField(field.getName());
} catch (NoSuchFieldException e) {
builder.add(field.getName());
}
}
ARABIC_FIELDS = builder.build();
}
private final boolean cached;
private final JsonDeserializer
© 2015 - 2024 Weber Informatics LLC | Privacy Policy