Search in sources :

Example 46 with JavaType

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

the class ClassUtils method createInterface.

private static Class<?> createInterface(Swagger swagger, ClassLoader classLoader, String packageName, String intfName) {
    ClassConfig classConfig = new ClassConfig();
    classConfig.setClassName(intfName);
    classConfig.setIntf(true);
    for (Path path : swagger.getPaths().values()) {
        for (Operation operation : path.getOperations()) {
            // 参数可能重名,所以packageName必须跟operation相关才能隔离
            String opPackageName = packageName + "." + operation.getOperationId();
            Response result = operation.getResponses().get(SwaggerConst.SUCCESS_KEY);
            JavaType resultJavaType = ConverterMgr.findJavaType(classLoader, opPackageName, swagger, result.getSchema());
            MethodConfig methodConfig = new MethodConfig();
            methodConfig.setName(operation.getOperationId());
            methodConfig.setResult(resultJavaType);
            for (Parameter parameter : operation.getParameters()) {
                String paramName = parameter.getName();
                paramName = correctMethodParameterName(paramName);
                JavaType paramJavaType = ConverterMgr.findJavaType(classLoader, opPackageName, swagger, parameter);
                methodConfig.addParameter(paramName, paramJavaType);
            }
            classConfig.addMethod(methodConfig);
        }
    }
    return JavassistUtils.createClass(classLoader, classConfig);
}
Also used : Path(io.swagger.models.Path) Response(io.swagger.models.Response) MethodConfig(org.apache.servicecomb.common.javassist.MethodConfig) JavaType(com.fasterxml.jackson.databind.JavaType) ClassConfig(org.apache.servicecomb.common.javassist.ClassConfig) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation)

Example 47 with JavaType

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

the class TestModelImplConverter method getOrCreateType.

@Test
public void getOrCreateType(@Mocked Swagger swagger) {
    String canonical = "name-";
    ModelImpl model = new ModelImpl();
    model.getVendorExtensions().put(SwaggerConst.EXT_JAVA_CLASS, canonical);
    JavaType type = converter.getOrCreateType(new ClassLoader() {
    }, null, swagger, model);
    Assert.assertEquals("name_", type.getRawClass().getName());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ModelImpl(io.swagger.models.ModelImpl) Test(org.junit.Test)

Example 48 with JavaType

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

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 49 with JavaType

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

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(org.apache.servicecomb.codec.protobuf.jackson.StandardObjectWriter) StandardObjectReader(org.apache.servicecomb.codec.protobuf.jackson.StandardObjectReader)

Example 50 with JavaType

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

the class StandardResultCodec method init.

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

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