use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.
the class RequiredDistributionJsonDeserializer method deserialize.
@Override
public RequiredDistribution deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
DistributionType type = DistributionType.valueOf(jsonNode.get("type").asText().toUpperCase());
switch(type) {
case ANY:
return InputProperty.ANY_DISTRIBUTION;
case SINGLETON:
return InputProperty.SINGLETON_DISTRIBUTION;
case BROADCAST:
return InputProperty.BROADCAST_DISTRIBUTION;
case UNKNOWN:
return InputProperty.UNKNOWN_DISTRIBUTION;
case HASH:
JsonNode keysNode = jsonNode.get("keys");
if (keysNode == null) {
throw new TableException("Hash distribution requires non-empty hash keys.");
}
int[] keys = new int[keysNode.size()];
for (int i = 0; i < keysNode.size(); ++i) {
keys[i] = keysNode.get(i).asInt();
}
return InputProperty.hashDistribution(keys);
default:
throw new TableException("Unsupported distribution type: " + type);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.
the class ResolvedExpressionJsonDeserializer method deserialize.
@Override
public ResolvedExpression deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
ObjectNode jsonNode = jsonParser.readValueAsTree();
String expressionType = Optional.ofNullable(jsonNode.get(TYPE)).map(JsonNode::asText).orElse(TYPE_REX_NODE_EXPRESSION);
if (TYPE_REX_NODE_EXPRESSION.equals(expressionType)) {
return deserializeRexNodeExpression(jsonNode, jsonParser.getCodec(), ctx);
} else {
throw new ValidationException(String.format("Expression '%s' cannot be deserialized. " + "Currently, only SQL expressions can be deserialized from the persisted plan.", jsonNode));
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project druid by druid-io.
the class GroupByQueryQueryToolChest method decorateObjectMapper.
@Override
public ObjectMapper decorateObjectMapper(final ObjectMapper objectMapper, final GroupByQuery query) {
final boolean resultAsArray = query.getContextBoolean(GroupByQueryConfig.CTX_KEY_ARRAY_RESULT_ROWS, false);
// Serializer that writes array- or map-based rows as appropriate, based on the "resultAsArray" setting.
final JsonSerializer<ResultRow> serializer = new JsonSerializer<ResultRow>() {
@Override
public void serialize(final ResultRow resultRow, final JsonGenerator jg, final SerializerProvider serializers) throws IOException {
if (resultAsArray) {
jg.writeObject(resultRow.getArray());
} else {
jg.writeObject(resultRow.toMapBasedRow(query));
}
}
};
// Deserializer that can deserialize either array- or map-based rows.
final JsonDeserializer<ResultRow> deserializer = new JsonDeserializer<ResultRow>() {
@Override
public ResultRow deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
if (jp.isExpectedStartObjectToken()) {
final Row row = jp.readValueAs(Row.class);
return ResultRow.fromLegacyRow(row, query);
} else {
return ResultRow.of(jp.readValueAs(Object[].class));
}
}
};
class GroupByResultRowModule extends SimpleModule {
private GroupByResultRowModule() {
addSerializer(ResultRow.class, serializer);
addDeserializer(ResultRow.class, deserializer);
}
}
final ObjectMapper newObjectMapper = objectMapper.copy();
newObjectMapper.registerModule(new GroupByResultRowModule());
return newObjectMapper;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project java-chassis by ServiceComb.
the class ArgWrapperJavaType method readValue.
public Map<String, Object> readValue(ObjectMapper mapper, String json) throws IOException {
Map<String, Object> args = new LinkedHashMap<>();
JsonParser jp = mapper.getFactory().createParser(json);
DeserializationContext deserializationContext = ObjectMapperUtils.createDeserializationContext(mapper, jp);
jp.nextToken();
for (String fieldName = jp.nextFieldName(); fieldName != null; fieldName = jp.nextFieldName()) {
jp.nextToken();
ArgInfo argInfo = argInfos.get(fieldName);
if (argInfo == null) {
continue;
}
if (argInfo.deserializer == null) {
argInfo.deserializer = deserializationContext.findRootValueDeserializer(argInfo.javaType);
}
args.put(fieldName, argInfo.deserializer.deserialize(jp, deserializationContext));
}
return args;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project sts4 by spring-projects.
the class JSON method pathAsJson.
private static SimpleModule pathAsJson() {
SimpleModule m = new SimpleModule();
m.addSerializer(Path.class, new JsonSerializer<Path>() {
@Override
public void serialize(Path path, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
gen.writeString(path.toString());
}
});
m.addDeserializer(Path.class, new JsonDeserializer<Path>() {
@Override
public Path deserialize(JsonParser parse, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
return Paths.get(parse.getText());
}
});
return m;
}
Aggregations