Search in sources :

Example 6 with JavaType

use of 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 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 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 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 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)264 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 Test (org.junit.Test)27 IOException (java.io.IOException)21 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)20 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)17 ArrayList (java.util.ArrayList)17 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)15 Property (io.swagger.models.properties.Property)15 List (java.util.List)15 Map (java.util.Map)13 StringProperty (io.swagger.models.properties.StringProperty)12 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)10 ModelImpl (io.swagger.models.ModelImpl)10 MapProperty (io.swagger.models.properties.MapProperty)10 Method (java.lang.reflect.Method)10 Type (java.lang.reflect.Type)10 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)9 ArrayProperty (io.swagger.models.properties.ArrayProperty)9 IntegerProperty (io.swagger.models.properties.IntegerProperty)9