Search in sources :

Example 6 with BeanProperty

use of com.fasterxml.jackson.databind.BeanProperty in project torodb by torodb.

the class AbstractBackendSerializer method depositSchemaProperty.

private void depositSchemaProperty(JsonObjectFormatVisitor v, String name, JavaType type) throws JsonMappingException {
    BeanProperty prop = new BeanProperty.Std(PropertyName.construct(name), type, null, null, null, PropertyMetadata.STD_OPTIONAL) {

        @Override
        public void depositSchemaProperty(JsonObjectFormatVisitor v) {
            try {
                if (v != null) {
                    if (isRequired()) {
                        v.property(this);
                    } else {
                        v.optionalProperty(this);
                    }
                }
            } catch (JsonMappingException jsonMappingException) {
                throw new RuntimeException(jsonMappingException);
            }
        }
    };
    prop.depositSchemaProperty(v);
}
Also used : JsonObjectFormatVisitor(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) BeanProperty(com.fasterxml.jackson.databind.BeanProperty)

Example 7 with BeanProperty

use of com.fasterxml.jackson.databind.BeanProperty in project druid by druid-io.

the class GceAutoScalerTest method testConfig.

@Test
public void testConfig() {
    final String json = "{\n" + "   \"envConfig\" : {\n" + "      \"numInstances\" : 1,\n" + "      \"projectId\" : \"super-project\",\n" + "      \"zoneName\" : \"winkie-country\",\n" + "      \"managedInstanceGroupName\" : \"druid-mig\"\n" + "   },\n" + "   \"maxNumWorkers\" : 4,\n" + "   \"minNumWorkers\" : 2,\n" + "   \"type\" : \"gce\"\n" + "}";
    final ObjectMapper objectMapper = new DefaultObjectMapper().registerModules((Iterable<Module>) new GceModule().getJacksonModules());
    objectMapper.setInjectableValues(new InjectableValues() {

        @Override
        public Object findInjectableValue(Object o, DeserializationContext deserializationContext, BeanProperty beanProperty, Object o1) {
            return null;
        }
    });
    try {
        final GceAutoScaler autoScaler = (GceAutoScaler) objectMapper.readValue(json, AutoScaler.class);
        verifyAutoScaler(autoScaler);
        final GceAutoScaler roundTripAutoScaler = (GceAutoScaler) objectMapper.readValue(objectMapper.writeValueAsBytes(autoScaler), AutoScaler.class);
        verifyAutoScaler(roundTripAutoScaler);
        Assert.assertEquals("Round trip equals", autoScaler, roundTripAutoScaler);
    } catch (Exception e) {
        Assert.fail(StringUtils.format("Got exception in test %s", e.getMessage()));
    }
}
Also used : InjectableValues(com.fasterxml.jackson.databind.InjectableValues) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) BeanProperty(com.fasterxml.jackson.databind.BeanProperty) 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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 8 with BeanProperty

use of com.fasterxml.jackson.databind.BeanProperty 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 9 with BeanProperty

use of com.fasterxml.jackson.databind.BeanProperty 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 10 with BeanProperty

use of com.fasterxml.jackson.databind.BeanProperty in project beam by apache.

the class PipelineOptionsFactory method computeDeserializerForMethod.

private static JsonDeserializer<Object> computeDeserializerForMethod(Method method) {
    try {
        BeanProperty prop = createBeanProperty(method);
        AnnotatedMember annotatedMethod = prop.getMember();
        DefaultDeserializationContext context = DESERIALIZATION_CONTEXT.get();
        Object maybeDeserializerClass = context.getAnnotationIntrospector().findDeserializer(annotatedMethod);
        JsonDeserializer<Object> jsonDeserializer = context.deserializerInstance(annotatedMethod, maybeDeserializerClass);
        if (jsonDeserializer == null) {
            jsonDeserializer = context.findContextualValueDeserializer(prop.getType(), prop);
        }
        TypeDeserializer typeDeserializer = context.getFactory().findTypeDeserializer(context.getConfig(), prop.getType());
        if (typeDeserializer != null) {
            jsonDeserializer = new TypeWrappedDeserializer(typeDeserializer, jsonDeserializer);
        }
        return jsonDeserializer;
    } catch (JsonMappingException e) {
        throw new RuntimeException(e);
    }
}
Also used : DefaultDeserializationContext(com.fasterxml.jackson.databind.deser.DefaultDeserializationContext) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) TypeDeserializer(com.fasterxml.jackson.databind.jsontype.TypeDeserializer) TypeWrappedDeserializer(com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer) BeanProperty(com.fasterxml.jackson.databind.BeanProperty)

Aggregations

BeanProperty (com.fasterxml.jackson.databind.BeanProperty)11 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)5 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Test (org.junit.Test)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)4 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)3 JavaType (com.fasterxml.jackson.databind.JavaType)2 Module (com.fasterxml.jackson.databind.Module)2 AnnotatedMember (com.fasterxml.jackson.databind.introspect.AnnotatedMember)2 TypeDeserializer (com.fasterxml.jackson.databind.jsontype.TypeDeserializer)2 EC2AutoScaler (io.druid.indexing.overlord.autoscaling.ec2.EC2AutoScaler)2 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)2 IOException (java.io.IOException)2 AutoScaler (org.apache.druid.indexing.overlord.autoscaling.AutoScaler)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonPointer (com.fasterxml.jackson.core.JsonPointer)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)1 PropertyName (com.fasterxml.jackson.databind.PropertyName)1