tech.ytsaurus.client.DefaultSerializationResolver Maven / Gradle / Ivy
The newest version!
package tech.ytsaurus.client;
import tech.ytsaurus.client.rows.ConsumerSource;
import tech.ytsaurus.client.rows.WireRowSerializer;
import tech.ytsaurus.client.rows.WireRowsetDeserializer;
import tech.ytsaurus.client.rows.YTreeDeserializer;
import tech.ytsaurus.client.rows.YTreeWireRowSerializer;
import tech.ytsaurus.core.rows.YTreeMapNodeSerializer;
import tech.ytsaurus.core.rows.YTreeRowSerializer;
import tech.ytsaurus.core.rows.YTreeSerializer;
import tech.ytsaurus.core.tables.TableSchema;
import tech.ytsaurus.ysontree.YTree;
import tech.ytsaurus.ysontree.YTreeMapNode;
import tech.ytsaurus.ysontree.YTreeNode;
public class DefaultSerializationResolver implements SerializationResolver {
private static final SerializationResolver INSTANCE = new DefaultSerializationResolver();
private DefaultSerializationResolver() {
}
public static SerializationResolver getInstance() {
return INSTANCE;
}
@Override
public YTreeRowSerializer forClass(Class clazz, TableSchema schema) {
if (clazz.equals(YTreeMapNode.class)) {
return (YTreeRowSerializer) new YTreeMapNodeSerializer();
} else {
throw new IllegalArgumentException("Unsupported class: " + clazz);
}
}
@Override
public WireRowsetDeserializer createWireRowDeserializer(YTreeSerializer serializer) {
return new YTreeDeserializer<>(serializer);
}
@Override
public WireRowsetDeserializer createWireRowDeserializer(TableSchema schema,
YTreeSerializer serializer,
ConsumerSource consumer) {
YTreeDeserializer deserializer = new YTreeDeserializer<>(serializer, consumer);
deserializer.updateSchema(schema);
return deserializer;
}
@Override
public WireRowSerializer createWireRowSerializer(YTreeSerializer serializer) {
return YTreeWireRowSerializer.forClass(serializer);
}
@Override
public TableSchema asTableSchema(YTreeSerializer serializer) {
return TableSchema.builder().build();
}
@Override
public YTreeNode toTree(Object value) {
if (value instanceof YTreeNode) {
return (YTreeNode) value;
} else {
return YTree.builder().value(value).build();
}
}
}