Search in sources :

Example 1 with JsonCreator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator in project presto by prestodb.

the class NullableValue method fromSerializable.

// Jackson deserialization only
@JsonCreator
public static NullableValue fromSerializable(@JsonProperty("serializable") Serializable serializable) {
    Type type = serializable.getType();
    Block block = serializable.getBlock();
    return new NullableValue(type, block == null ? null : Utils.blockToNativeValue(type, block));
}
Also used : Type(com.facebook.presto.spi.type.Type) Block(com.facebook.presto.spi.block.Block) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Example 2 with JsonCreator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator in project td-client-java by treasure-data.

the class TDQuery method fromObject.

@JsonCreator
public static TDQuery fromObject(JsonNode value) {
    // embulk job have nested json object
    try {
        StringWriter s = new StringWriter();
        new ObjectMapper().writeValue(s, value);
        s.close();
        return new TDQuery(s.toString());
    } catch (java.io.IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : StringWriter(java.io.StringWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Example 3 with JsonCreator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator in project embulk by embulk.

the class ByteSize method parseByteSize.

@JsonCreator
public static ByteSize parseByteSize(String size) {
    Preconditions.checkNotNull(size, "size is null");
    Preconditions.checkArgument(!size.isEmpty(), "size is empty");
    Matcher matcher = PATTERN.matcher(size);
    if (!matcher.matches()) {
        throw new IllegalArgumentException("Invalid byte size string '" + size + "'");
    }
    // NumberFormatException extends IllegalArgumentException.
    double value = Double.parseDouble(matcher.group(1));
    String unitString = matcher.group(2);
    if (unitString.isEmpty()) {
        return new ByteSize(value, Unit.BYTES);
    } else {
        String upperUnitString = unitString.toUpperCase(Locale.ENGLISH);
        for (Unit unit : Unit.values()) {
            if (unit.getUnitString().toUpperCase(Locale.ENGLISH).equals(upperUnitString)) {
                return new ByteSize(value, unit);
            }
        }
    }
    throw new IllegalArgumentException("Unknown unit '" + unitString + "'");
}
Also used : Matcher(java.util.regex.Matcher) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Example 4 with JsonCreator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator in project druid by druid-io.

the class InlineDataSource method fromJson.

/**
 * Factory method for Jackson. Used for inline datasources that were originally encoded as JSON. Private because
 * non-Jackson callers should use {@link #fromIterable}.
 */
@JsonCreator
private static InlineDataSource fromJson(@JsonProperty("columnNames") List<String> columnNames, @JsonProperty("columnTypes") List<ColumnType> columnTypes, @JsonProperty("rows") List<Object[]> rows) {
    Preconditions.checkNotNull(columnNames, "'columnNames' must be nonnull");
    if (columnTypes != null && columnNames.size() != columnTypes.size()) {
        throw new IAE("columnNames and columnTypes must be the same length");
    }
    final RowSignature.Builder builder = RowSignature.builder();
    for (int i = 0; i < columnNames.size(); i++) {
        final String name = columnNames.get(i);
        final ColumnType type = columnTypes != null ? columnTypes.get(i) : null;
        builder.add(name, type);
    }
    return new InlineDataSource(rows, builder.build());
}
Also used : ColumnType(org.apache.druid.segment.column.ColumnType) IAE(org.apache.druid.java.util.common.IAE) RowSignature(org.apache.druid.segment.column.RowSignature) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Example 5 with JsonCreator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator in project batfish by batfish.

the class Prefix method parse.

@JsonCreator
public static Prefix parse(String text) {
    String[] parts = text.split("/");
    if (parts.length != 2) {
        throw new BatfishException("Invalid prefix string: \"" + text + "\"");
    }
    Ip ip = new Ip(parts[0]);
    int prefixLength;
    try {
        prefixLength = Integer.parseInt(parts[1]);
    } catch (NumberFormatException e) {
        throw new BatfishException("Invalid prefix length: \"" + parts[1] + "\"", e);
    }
    return new Prefix(ip, prefixLength);
}
Also used : BatfishException(org.batfish.common.BatfishException) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator)

Aggregations

JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)15 Matcher (java.util.regex.Matcher)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Block (com.facebook.presto.common.block.Block)1 Type (com.facebook.presto.common.type.Type)1 Block (com.facebook.presto.spi.block.Block)1 Type (com.facebook.presto.spi.type.Type)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 JsonSetter (com.fasterxml.jackson.annotation.JsonSetter)1 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonPOJOBuilder (com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder)1 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)1 DataInput (java.io.DataInput)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1