Package com.facebook.presto.jdbc.internal.jackson.databind.deser.std

Source Code of com.facebook.presto.jdbc.internal.jackson.databind.deser.std.JsonLocationInstantiator

package com.facebook.presto.jdbc.internal.jackson.databind.deser.std;

import com.facebook.presto.jdbc.internal.jackson.core.JsonLocation;
import com.facebook.presto.jdbc.internal.jackson.databind.DeserializationConfig;
import com.facebook.presto.jdbc.internal.jackson.databind.DeserializationContext;
import com.facebook.presto.jdbc.internal.jackson.databind.JavaType;
import com.facebook.presto.jdbc.internal.jackson.databind.PropertyMetadata;
import com.facebook.presto.jdbc.internal.jackson.databind.PropertyName;
import com.facebook.presto.jdbc.internal.jackson.databind.deser.CreatorProperty;
import com.facebook.presto.jdbc.internal.jackson.databind.deser.ValueInstantiator;

/**
* For {@link JsonLocation}, we should be able to just implement
* {@link ValueInstantiator} (not that explicit one would be very
* hard but...)
*/
public class JsonLocationInstantiator extends ValueInstantiator
{
    @Override
    public String getValueTypeDesc() {
        return JsonLocation.class.getName();
    }
   
    @Override
    public boolean canCreateFromObjectWith() { return true; }
   
    @Override
    public CreatorProperty[] getFromObjectArguments(DeserializationConfig config) {
        JavaType intType = config.constructType(Integer.TYPE);
        JavaType longType = config.constructType(Long.TYPE);
        return  new CreatorProperty[] {
                creatorProp("sourceRef", config.constructType(Object.class), 0),
                creatorProp("byteOffset", longType, 1),
                creatorProp("charOffset", longType, 2),
                creatorProp("lineNr", intType, 3),
                creatorProp("columnNr", intType, 4)
        };
    }

    private static CreatorProperty creatorProp(String name, JavaType type, int index) {
        return new CreatorProperty(new PropertyName(name), type, null,
                null, null, null, index, null, PropertyMetadata.STD_REQUIRED);
    }
   
    @Override
    public Object createFromObjectWith(DeserializationContext ctxt, Object[] args) {
        return new JsonLocation(args[0], _long(args[1]), _long(args[2]),
                _int(args[3]), _int(args[4]));
    }

    private final static long _long(Object o) {
        return (o == null) ? 0L : ((Number) o).longValue();
    }

    private final static int _int(Object o) {
        return (o == null) ? 0 : ((Number) o).intValue();
    }
}
TOP

Related Classes of com.facebook.presto.jdbc.internal.jackson.databind.deser.std.JsonLocationInstantiator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.