Search in sources :

Example 36 with DeserializationContext

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

the class WorkerBehaviorConfigTest method testSerde.

@Test
public void testSerde() throws Exception {
    DefaultWorkerBehaviorConfig config = new DefaultWorkerBehaviorConfig(new FillCapacityWithAffinityWorkerSelectStrategy(new AffinityConfig(ImmutableMap.of("foo", ImmutableSet.of("localhost")), false)), new EC2AutoScaler(7, 11, new EC2EnvironmentConfig("us-east-1a", new EC2NodeData("amiid", "instanceType", 3, 5, Collections.singletonList("securityGroupIds"), "keyNames", "subnetId", null, null), new StringEC2UserData("availZone", "replace", "version")), null, null));
    final ObjectMapper mapper = new DefaultObjectMapper();
    mapper.registerSubtypes(EC2AutoScaler.class);
    mapper.setInjectableValues(new InjectableValues() {

        @Override
        public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) {
            return null;
        }
    });
    Assert.assertEquals(config, mapper.readValue(mapper.writeValueAsBytes(config), DefaultWorkerBehaviorConfig.class));
}
Also used : EC2EnvironmentConfig(org.apache.druid.indexing.overlord.autoscaling.ec2.EC2EnvironmentConfig) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) EC2AutoScaler(org.apache.druid.indexing.overlord.autoscaling.ec2.EC2AutoScaler) BeanProperty(com.fasterxml.jackson.databind.BeanProperty) StringEC2UserData(org.apache.druid.indexing.overlord.autoscaling.ec2.StringEC2UserData) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) EC2NodeData(org.apache.druid.indexing.overlord.autoscaling.ec2.EC2NodeData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 37 with DeserializationContext

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

the class EC2AutoScalerSerdeTest method testSerde.

@Test
public void testSerde() throws Exception {
    final ObjectMapper objectMapper = new DefaultObjectMapper().registerModules((Iterable<Module>) new EC2Module().getJacksonModules());
    objectMapper.setInjectableValues(new InjectableValues() {

        @Override
        public Object findInjectableValue(Object o, DeserializationContext deserializationContext, BeanProperty beanProperty, Object o1) {
            return null;
        }
    });
    final EC2AutoScaler autoScaler = (EC2AutoScaler) objectMapper.readValue(json, AutoScaler.class);
    verifyAutoScaler(autoScaler);
    final EC2AutoScaler roundTripAutoScaler = (EC2AutoScaler) objectMapper.readValue(objectMapper.writeValueAsBytes(autoScaler), AutoScaler.class);
    verifyAutoScaler(roundTripAutoScaler);
    Assert.assertEquals("Round trip equals", autoScaler, roundTripAutoScaler);
}
Also used : DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Module(com.fasterxml.jackson.databind.Module) AutoScaler(org.apache.druid.indexing.overlord.autoscaling.AutoScaler) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) BeanProperty(com.fasterxml.jackson.databind.BeanProperty) Test(org.junit.Test)

Example 38 with DeserializationContext

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.

the class JobResultDeserializer method deserialize.

@Override
public JobResult deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
    JobID jobId = null;
    ApplicationStatus applicationStatus = ApplicationStatus.UNKNOWN;
    long netRuntime = -1;
    SerializedThrowable serializedThrowable = null;
    Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = null;
    while (true) {
        final JsonToken jsonToken = p.nextToken();
        assertNotEndOfInput(p, jsonToken);
        if (jsonToken == JsonToken.END_OBJECT) {
            break;
        }
        final String fieldName = p.getValueAsString();
        switch(fieldName) {
            case JobResultSerializer.FIELD_NAME_JOB_ID:
                assertNextToken(p, JsonToken.VALUE_STRING);
                jobId = jobIdDeserializer.deserialize(p, ctxt);
                break;
            case JobResultSerializer.FIELD_NAME_APPLICATION_STATUS:
                assertNextToken(p, JsonToken.VALUE_STRING);
                applicationStatus = ApplicationStatus.valueOf(p.getValueAsString().toUpperCase());
                break;
            case JobResultSerializer.FIELD_NAME_NET_RUNTIME:
                assertNextToken(p, JsonToken.VALUE_NUMBER_INT);
                netRuntime = p.getLongValue();
                break;
            case JobResultSerializer.FIELD_NAME_ACCUMULATOR_RESULTS:
                assertNextToken(p, JsonToken.START_OBJECT);
                accumulatorResults = parseAccumulatorResults(p, ctxt);
                break;
            case JobResultSerializer.FIELD_NAME_FAILURE_CAUSE:
                assertNextToken(p, JsonToken.START_OBJECT);
                serializedThrowable = serializedThrowableDeserializer.deserialize(p, ctxt);
                break;
            default:
        }
    }
    try {
        return new JobResult.Builder().jobId(jobId).applicationStatus(applicationStatus).netRuntime(netRuntime).accumulatorResults(accumulatorResults).serializedThrowable(serializedThrowable).build();
    } catch (final RuntimeException e) {
        throw new JsonMappingException(null, "Could not deserialize " + JobResult.class.getSimpleName(), e);
    }
}
Also used : JobResult(org.apache.flink.runtime.jobmaster.JobResult) SerializedValue(org.apache.flink.util.SerializedValue) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) JsonMappingException(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException) JsonToken(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken) JobID(org.apache.flink.api.common.JobID) SerializedThrowable(org.apache.flink.util.SerializedThrowable)

Example 39 with DeserializationContext

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.

the class ResolvedSchemaJsonDeserializer method deserialize.

@Override
public ResolvedSchema deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
    ObjectNode jsonNode = jsonParser.readValueAsTree();
    List<Column> columns = ctx.readValue(traverse(jsonNode.required(COLUMNS), jsonParser.getCodec()), ctx.getTypeFactory().constructCollectionType(List.class, Column.class));
    List<WatermarkSpec> watermarkSpecs = ctx.readValue(traverse(jsonNode.required(WATERMARK_SPECS), jsonParser.getCodec()), ctx.getTypeFactory().constructCollectionType(List.class, WatermarkSpec.class));
    UniqueConstraint primaryKey = deserializeOptionalField(jsonNode, PRIMARY_KEY, UniqueConstraint.class, jsonParser.getCodec(), ctx).orElse(null);
    return new ResolvedSchema(columns, watermarkSpecs, primaryKey);
}
Also used : ObjectNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode) WatermarkSpec(org.apache.flink.table.catalog.WatermarkSpec) Column(org.apache.flink.table.catalog.Column) UniqueConstraint(org.apache.flink.table.catalog.UniqueConstraint) List(java.util.List) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema)

Example 40 with DeserializationContext

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.

the class RexNodeJsonDeserializer method deserialize.

@Override
public RexNode deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
    final JsonNode jsonNode = jsonParser.readValueAsTree();
    final SerdeContext serdeContext = SerdeContext.get(ctx);
    return deserialize(jsonNode, serdeContext);
}
Also used : JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)

Aggregations

DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)28 JsonParser (com.fasterxml.jackson.core.JsonParser)21 IOException (java.io.IOException)17 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 Test (org.junit.Test)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)7 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)7 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 BeanProperty (com.fasterxml.jackson.databind.BeanProperty)6 StdDeserializer (com.fasterxml.jackson.databind.deser.std.StdDeserializer)6 Map (java.util.Map)6 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)5 List (java.util.List)5 ObjectNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 Iterator (java.util.Iterator)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3