Search in sources :

Example 6 with JavaType

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

the class AbstractFieldCodec method initFieldMap.

private void initFieldMap(ProtobufSchema schema, Type[] types) {
    Iterator<ProtobufField> fieldIter = schema.getRootType().fields().iterator();
    for (int idx = 0; idx < schema.getRootType().getFieldCount(); idx++) {
        JavaType type = TypeFactory.defaultInstance().constructType(types[idx]);
        ProtobufField field = fieldIter.next();
        ReaderHelpData helpData = new ReaderHelpData();
        helpData.index = idx;
        helpData.deser = ((CseObjectReader) reader).findDeserializer(type);
        readerHelpDataMap.put(field.name, helpData);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ProtobufField(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField)

Example 7 with JavaType

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

the class StandardParamCodec method init.

@Override
public void init(ProtobufSchema schema, Type... types) {
    writer = ProtobufManager.getMapper().writer(schema);
    reader = ProtobufManager.getMapper().reader(schema);
    // 需要考虑没参数的场景
    if (types.length == 1) {
        JavaType javaType = TypeFactory.defaultInstance().constructType(types[0]);
        writer = new StandardObjectWriter(writer.forType(javaType));
        reader = new StandardObjectReader(reader.forType(javaType));
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) StandardObjectWriter(io.servicecomb.codec.protobuf.jackson.StandardObjectWriter) StandardObjectReader(io.servicecomb.codec.protobuf.jackson.StandardObjectReader)

Example 8 with JavaType

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

the class ResponseMeta method init.

public void init(ClassLoader classLoader, String packageName, Swagger swagger, Response response) {
    if (javaType == null) {
        Property property = response.getSchema();
        javaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, property);
    }
    if (response.getHeaders() == null) {
        return;
    }
    for (Entry<String, Property> entry : response.getHeaders().entrySet()) {
        JavaType headerJavaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, entry.getValue());
        headers.put(entry.getKey(), headerJavaType);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) Property(io.swagger.models.properties.Property)

Example 9 with JavaType

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

the class QueryProcessorCreator method create.

@Override
public ParamValueProcessor create(String paramValue, Type genericParamType) {
    JavaType targetType = TypeFactory.defaultInstance().constructType(genericParamType);
    Class<?> rawCls = targetType.getRawClass();
    boolean isArrayOrCollection = rawCls.isArray() || Collection.class.isAssignableFrom(rawCls);
    return new QueryProcessor(paramValue, targetType, isArrayOrCollection);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) Collection(java.util.Collection)

Example 10 with JavaType

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

the class TestProduce method testProduce.

/**
	 * Test Produce
	 * 
	 * @throws Exception
	 */
@Test
public void testProduce() throws Exception {
    Assert.assertEquals("produce processor mgr", ProduceProcessorManager.INSTANCE.getName());
    Buffer oBuffer = ProduceProcessorManager.DEFAULT_PROCESSOR.encodeResponse("test");
    OutputStream oOutputStream = new BufferOutputStream();
    ProduceProcessorManager.DEFAULT_PROCESSOR.encodeResponse(oOutputStream, "test2");
    JavaType targetType = TypeFactory.defaultInstance().constructType(String.class);
    InputStream oInputStream = new ByteArrayInputStream(("true").getBytes());
    ProduceProcessorManager.DEFAULT_PROCESSOR.decodeResponse(oInputStream, targetType);
    ProduceProcessorManager.PLAIN_PROCESSOR.encodeResponse(new BufferOutputStream(), "test2");
    Assert.assertNotEquals(null, ProduceProcessorManager.PLAIN_PROCESSOR.decodeResponse(oInputStream, targetType));
    oInputStream = new ByteArrayInputStream(("true").getBytes());
    Assert.assertNotEquals(null, ProduceProcessorManager.DEFAULT_PROCESSOR.decodeResponse(oInputStream, targetType));
    ProduceProcessorManager.DEFAULT_PROCESSOR.decodeResponse(oBuffer, targetType);
    Assert.assertEquals(null, ProduceProcessorManager.DEFAULT_PROCESSOR.encodeResponse(null));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) JavaType(com.fasterxml.jackson.databind.JavaType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) Test(org.junit.Test)

Aggregations

JavaType (com.fasterxml.jackson.databind.JavaType)322 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)36 Test (org.junit.Test)29 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)25 IOException (java.io.IOException)25 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)22 ArrayList (java.util.ArrayList)21 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)17 Property (io.swagger.models.properties.Property)16 List (java.util.List)16 Map (java.util.Map)14 ModelImpl (io.swagger.models.ModelImpl)13 StringProperty (io.swagger.models.properties.StringProperty)13 Annotation (java.lang.annotation.Annotation)12 Method (java.lang.reflect.Method)11 Type (java.lang.reflect.Type)11 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)10 BodyParameter (io.swagger.models.parameters.BodyParameter)10 MapProperty (io.swagger.models.properties.MapProperty)10 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)9