Search in sources :

Example 1 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 {
    WorkerBehaviorConfig config = new WorkerBehaviorConfig(new FillCapacityWithAffinityWorkerSelectStrategy(new FillCapacityWithAffinityConfig(ImmutableMap.of("foo", Arrays.asList("localhost")))), new EC2AutoScaler(7, 11, new EC2EnvironmentConfig("us-east-1a", new EC2NodeData("amiid", "instanceType", 3, 5, Arrays.asList("securityGroupIds"), "keyNames", "subnetId", null, null), new StringEC2UserData("availZone", "replace", "version")), null, null));
    final ObjectMapper mapper = new DefaultObjectMapper();
    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), WorkerBehaviorConfig.class));
}
Also used : EC2EnvironmentConfig(io.druid.indexing.overlord.autoscaling.ec2.EC2EnvironmentConfig) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) EC2AutoScaler(io.druid.indexing.overlord.autoscaling.ec2.EC2AutoScaler) BeanProperty(com.fasterxml.jackson.databind.BeanProperty) StringEC2UserData(io.druid.indexing.overlord.autoscaling.ec2.StringEC2UserData) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) EC2NodeData(io.druid.indexing.overlord.autoscaling.ec2.EC2NodeData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 2 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();
    objectMapper.setInjectableValues(new InjectableValues() {

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

Example 3 with DeserializationContext

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

the class TestAbstractDeserializer method testDeserialize.

@SuppressWarnings("unchecked")
@Test
public void testDeserialize() {
    boolean status = false;
    try {
        DeserializationContext ctxt = Mockito.mock(DeserializationContext.class);
        @SuppressWarnings("rawtypes") JsonDeserializer JsonDeserializer = Mockito.mock(JsonDeserializer.class);
        Object object = null;
        Mockito.when(jsonParser.nextFieldName()).thenReturn("abc", (String) null);
        Mockito.when(readerHelpData.getDeser()).thenReturn(JsonDeserializer);
        Mockito.when(JsonDeserializer.deserialize(jsonParser, ctxt)).thenReturn(object);
        Object deserializeObject = abstractDeserializer.deserialize(jsonParser, ctxt);
        Assert.assertNotNull(deserializeObject);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) Test(org.junit.Test)

Example 4 with DeserializationContext

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

the class IterableXDeserializer method deserialize.

@Override
public IterableX<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    JsonDeserializer deser = ctxt.findRootValueDeserializer(ctxt.getTypeFactory().constructArrayType(Object.class));
    Object o = deser.deserialize(p, ctxt);
    if (Vector.class.isAssignableFrom(elementType))
        return Vector.of((Object[]) o);
    if (Seq.class.isAssignableFrom(elementType))
        return Seq.of((Object[]) o);
    if (LazySeq.class.isAssignableFrom(elementType))
        return LazySeq.of((Object[]) o);
    if (LazyString.class.isAssignableFrom(elementType))
        return LazyString.fromLazySeq((LazySeq) LazySeq.of((Object[]) o));
    if (IntMap.class.isAssignableFrom(elementType))
        return IntMap.of((Object[]) o);
    if (ReactiveSeq.class.isAssignableFrom(elementType))
        return ReactiveSeq.of((Object[]) o);
    if (Streamable.class.isAssignableFrom(elementType))
        return Streamable.of((Object[]) o);
    if (BankersQueue.class.isAssignableFrom(elementType))
        return BankersQueue.of((Object[]) o);
    if (Bag.class.isAssignableFrom(elementType))
        return Bag.of((Object[]) o);
    if (cyclops.data.HashSet.class.isAssignableFrom(elementType))
        return HashSet.of((Object[]) o);
    if (cyclops.data.TrieSet.class.isAssignableFrom(elementType))
        return TrieSet.of((Object[]) o);
    if (cyclops.data.TreeSet.class.isAssignableFrom(elementType))
        return TreeSet.of((Comparator) Comparator.naturalOrder(), (Object[]) o);
    Optional<Method> m = streamMethod.computeIfAbsent(itX, c -> Stream.of(c.getMethods()).filter(method -> "of".equals(method.getName())).filter(method -> method.getParameterCount() == 1).filter(method -> method.getParameterTypes()[0].isArray()).findFirst().map(m2 -> {
        m2.setAccessible(true);
        return m2;
    }));
    IterableX x = m.map(mt -> (IterableX) new Invoker().executeMethod(o, mt, itX)).orElse(null);
    return x;
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser) AsArrayTypeDeserializer(com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer) cyclops.data(cyclops.data) MethodHandles(java.lang.invoke.MethodHandles) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) StdDeserializer(com.fasterxml.jackson.databind.deser.std.StdDeserializer) ReactiveSeq(cyclops.reactive.ReactiveSeq) Stream(java.util.stream.Stream) Streamable(cyclops.reactive.Streamable) CallSite(java.lang.invoke.CallSite) Map(java.util.Map) IterableX(com.oath.cyclops.types.traversable.IterableX) ExceptionSoftener(com.oath.cyclops.util.ExceptionSoftener) Optional(java.util.Optional) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) ObjectArrayDeserializer(com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer) Comparator(java.util.Comparator) Method(java.lang.reflect.Method) ConstantCallSite(java.lang.invoke.ConstantCallSite) cyclops.data(cyclops.data) IterableX(com.oath.cyclops.types.traversable.IterableX) Method(java.lang.reflect.Method) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) Comparator(java.util.Comparator)

Example 5 with DeserializationContext

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

the class PersistentMapDeserializer method deserialize.

@Override
public PersistentMap<?, ?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    JsonDeserializer deser = ctxt.findRootValueDeserializer(ctxt.getTypeFactory().constructRawMapType(Map.class));
    Object o = deser.deserialize(p, ctxt);
    if (HashMap.class.isAssignableFrom(mapType))
        return HashMap.fromMap((Map) o);
    if (TreeMap.class.isAssignableFrom(mapType))
        return TreeMap.fromMap((Comparator) Comparator.naturalOrder(), (Map) o);
    /**
     * if(TrieMap.class.isAssignableFrom(mapType))
     *      return TrieMap.fromMap((Map)o);
     *    if(LinkedMap.class.isAssignableFrom(mapType))
     *      return LinkedMap.fromMap((Map)o);
     */
    Optional<Method> m = streamMethod.computeIfAbsent(mapType, c -> Stream.of(c.getMethods()).filter(method -> "fromMap".equals(method.getName())).filter(method -> method.getParameterCount() == 1).filter(method -> method.getParameterTypes()[0].isAssignableFrom(Map.class)).findFirst().map(m2 -> {
        m2.setAccessible(true);
        return m2;
    }));
    PersistentMap<?, ?> x = m.map(mt -> (PersistentMap) new PersistentMapDeserializer.Invoker().executeMethod(o, mt, mapType)).orElse(null);
    return x;
}
Also used : DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) PersistentMap(com.oath.cyclops.types.persistent.PersistentMap) JsonParser(com.fasterxml.jackson.core.JsonParser) HashMap(cyclops.data.HashMap) MethodHandles(java.lang.invoke.MethodHandles) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) StdDeserializer(com.fasterxml.jackson.databind.deser.std.StdDeserializer) TreeMap(cyclops.data.TreeMap) Stream(java.util.stream.Stream) CallSite(java.lang.invoke.CallSite) Map(java.util.Map) ExceptionSoftener(com.oath.cyclops.util.ExceptionSoftener) Optional(java.util.Optional) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) Comparator(java.util.Comparator) Method(java.lang.reflect.Method) ConstantCallSite(java.lang.invoke.ConstantCallSite) PersistentMap(com.oath.cyclops.types.persistent.PersistentMap) Method(java.lang.reflect.Method) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) PersistentMap(com.oath.cyclops.types.persistent.PersistentMap) HashMap(cyclops.data.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(cyclops.data.TreeMap) Map(java.util.Map) Comparator(java.util.Comparator)

Aggregations

DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)27 JsonParser (com.fasterxml.jackson.core.JsonParser)20 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 StdDeserializer (com.fasterxml.jackson.databind.deser.std.StdDeserializer)6 Map (java.util.Map)6 BeanProperty (com.fasterxml.jackson.databind.BeanProperty)5 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)5 ObjectNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Iterator (java.util.Iterator)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)3