package io.ebeaninternal.server.deploy;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import io.ebean.bean.EntityBean;
import io.ebeaninternal.api.json.SpiJsonReader;
import java.io.IOException;
import java.util.LinkedHashMap;
class BeanPropertyAssocManyJsonTransient {
void jsonReadUsingObjectMapper(BeanPropertyAssocMany<?> many, SpiJsonReader readJson, EntityBean parentBean) throws IOException {
ObjectMapper mapper = readJson.getObjectMapper();
ManyType manyType = many.getManyType();
Object value;
if (manyType.isMap()) {
TypeFactory typeFactory = mapper.getTypeFactory();
JavaType target = typeFactory.constructType(many.getTargetType());
MapType jacksonType = typeFactory.constructMapType(LinkedHashMap.class, TypeFactory.unknownType(), target);
value = mapper.readValue(readJson.getParser(), jacksonType);
} else {
CollectionType jacksonType = mapper.getTypeFactory().constructCollectionType(manyType.getCollectionType(), many.getTargetType());
value = mapper.readValue(readJson.getParser(), jacksonType);
}
many.setValue(parentBean, value);
}
}