当前位置: 首页>>代码示例>>Java>>正文


Java JavaType类代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.JavaType的典型用法代码示例。如果您正苦于以下问题:Java JavaType类的具体用法?Java JavaType怎么用?Java JavaType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JavaType类属于com.fasterxml.jackson.databind包,在下文中一共展示了JavaType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: supports

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
@Override
protected boolean supports(Class<?> clazz) {
    JavaType javaType = getJavaType(clazz);
    AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
    if (this.objectMapper.canDeserialize(javaType, causeRef)) {
        return true;
    }
    Throwable cause = causeRef.get();
    if (cause != null) {
        String msg = "Failed to evaluate deserialization for type " + javaType;
        if (logger.isDebugEnabled()) {
            logger.warn(msg, cause);
        }
        else {
            logger.warn(msg + ": " + cause);
        }
    }
    return false;
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:20,代码来源:AbstractJackson2HttpMessageReader.java

示例2: encode

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
@Override
public void encode(OutputStream out, Object object) throws Exception {
    Class<?> clazz = object.getClass();
    JsonGenerator generator = constructGenerator(out);
    JavaType type = mapper.getTypeFactory().constructType(clazz);
    ObjectWriter writer = mapper.writerFor(type);
    writer.writeValue(generator, object);
    generator.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:Jackson2AfterBurnCodec.java

示例3: i_should_get_all_users_with_the_following_properties

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
@Then("^I should get all users with the following properties: (.*)$")
public void i_should_get_all_users_with_the_following_properties(List<String> properties) throws IOException {
    ObjectMapper mapper = new ObjectMapper();

    JavaType type = mapper.getTypeFactory().constructCollectionType(List.class, User.class);
    List<User> users = mapper.readValue(httpWorld.loadResponse().getBody(), type);

    for (String property : properties) {
        assertThat(users, everyItem(HasProperty.hasProperty(property)));
    }
}
 
开发者ID:cmateosl,项目名称:role-api,代码行数:12,代码来源:UsersSteps.java

示例4: typeFromId

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
JavaType typeFromId(String id, TypeFactory typeFactory) throws IllegalStateException {
    String className = basePackage + "." + generateClassName(id);
    try {
        return typeFactory.constructType(typeFactory.findClass(className));
    } catch (ClassNotFoundException ex) {
        throw new IllegalStateException("Could not find event class for type " + id, ex);
    }
}
 
开发者ID:goodees,项目名称:goodees,代码行数:9,代码来源:ImmutableEventTypeResolver.java

示例5: modifyEnumDeserializer

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
@Override
public JsonDeserializer<?> modifyEnumDeserializer(DeserializationConfig config, JavaType type,
    BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
  if (Arrays.asList(Quality.class, Format.class).contains(type.getRawClass())) {
    return new EnumDeserializer((Class<? extends Enum>) type.getRawClass());
  }
  return super.modifyEnumDeserializer(config, type, beanDesc, deserializer);
}
 
开发者ID:dbmdz,项目名称:iiif-apis,代码行数:9,代码来源:DeserializerModifier.java

示例6: tryCoerceParam

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
@Override
public Optional<Object> tryCoerceParam(InvocationContext currentContext, int param, InputEvent input, MethodWrapper method) {

    Type type = method.getTargetMethod().getGenericParameterTypes()[param];
    JavaType javaType = objectMapper(currentContext).constructType(type);

    return Optional.ofNullable(input.consumeBody(inputStream -> {
        try {
            return objectMapper(currentContext).readValue(inputStream, javaType);
        } catch (IOException e) {
            throw coercionFailed(type, e);
        }
    }));

}
 
开发者ID:fnproject,项目名称:fdk-java,代码行数:16,代码来源:JacksonCoercion.java

示例7: init

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
@BeforeClass
public static void init() throws ParseException, IOException {
    logger.info("    Initializing RLP tests...");
    String json = getJSON("rlptest");

    Assume.assumeFalse("Local test is not available", json.equals(""));

    ObjectMapper mapper = new ObjectMapper();
    JavaType type = mapper.getTypeFactory().
            constructMapType(HashMap.class, String.class, RLPTestCase.class);

    TEST_SUITE = mapper.readValue(json, type);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:14,代码来源:LocalRLPTest.java

示例8: readJavaType

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
	try {
		return this.objectMapper.readValue(inputMessage.getBody(), javaType);
	}
	catch (IOException ex) {
		throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:MappingJackson2HttpMessageConverter.java

示例9: doConvert

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
@Override
public JavaType doConvert(ClassLoader classLoader, String packageName, Swagger swagger, Object property) {
  ArrayProperty arrayProperty = (ArrayProperty) property;

  return findJavaType(classLoader,
      packageName,
      swagger,
      arrayProperty.getItems(),
      arrayProperty.getUniqueItems());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:11,代码来源:ArrayPropertyConverter.java

示例10: getOrCreateEnumByNames

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
private static JavaType getOrCreateEnumByNames(ClassLoader classLoader, String packageName, List<String> enums) {
  String strEnums = enums.toString();

  synchronized (LOCK) {
    JavaType javaType = enumMap.get(strEnums);
    if (javaType != null) {
      return javaType;
    }

    String enumClsName = packageName + ".Enum" + enumMap.size();
    @SuppressWarnings("rawtypes")
    Class<? extends Enum> enumCls = JavassistUtils.createEnum(classLoader, enumClsName, enums);
    javaType = TypeFactory.defaultInstance().constructType(enumCls);
    enumMap.put(strEnums, javaType);

    return javaType;
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:StringPropertyConverter.java

示例11: doConvert

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
@Override
public JavaType doConvert(ClassLoader classLoader, String packageName, Swagger swagger, Object property) {
  StringProperty stringProperty = (StringProperty) property;

  List<String> enums = stringProperty.getEnum();
  return findJavaType(classLoader,
      packageName,
      swagger,
      stringProperty.getType(),
      stringProperty.getFormat(),
      enums);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:13,代码来源:StringPropertyConverter.java

示例12: bulkLinkedRead1Test

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
public static void bulkLinkedRead1Test() throws IOException {
    SugarRestClient client = new SugarRestClient(TestAccount.Url, TestAccount.Username, TestAccount.Password);

    // -------------------Read Account Link Contact-------------------
    int count = 10;
    SugarRestResponse response = LinkedModules.bulkReadAccountLinkContact(client, count);

    assertNotNull(response);
    assertEquals(response.getStatusCode(), HttpStatus.SC_OK);

    String jsonData = response.getJData();
    assertNull(response.getData());
    assertNotNull(jsonData);

    // Deserialize json data to custom object
    ObjectMapper mapper = JsonObjectMapper.getMapper();
    JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, CustomAcccount1.class) ;
    List<CustomAcccount1> customAccounts = mapper.readValue(jsonData, type);
    assertNotNull(customAccounts);
    assertEquals(customAccounts.size(), count);
}
 
开发者ID:mattkol,项目名称:SugarOnRest,代码行数:22,代码来源:LinkedModulesTests.java

示例13: implementDeserializeMethod

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
@Override
protected MethodSpec implementDeserializeMethod(TypeElement typeElement, Builder deserializeMethodBuilder) {
    Optional<DeserializationConstructs> constructs = loadConstructs(typeElement);
    if (!constructs.isPresent()) {
        return deserializeMethodBuilder.addStatement("return null").build();
    }

    TypeElement enumTypeElement = constructs.get().getEnumTypeElement();
    ImmutableList<Element> enumValueElements = constructs.get().getEnumValueElements();
    ExecutableElement enumValueAccessorMethod = constructs.get().getEnumValueAccessorMethod();
    ExecutableElement enumInstanceAccessorMethod = constructs.get().getEnumInstanceAccessorMethod();

    String memberVariableName = this.processorUtil.createMemberVariableName(enumValueAccessorMethod);

    deserializeMethodBuilder.addStatement("$T codec = $L.getCodec()", ObjectCodec.class, JSON_PARSER_PARAMETER_NAME)
            .addStatement("$T rootNode = codec.readTree($L)", JsonNode.class, JSON_PARSER_PARAMETER_NAME)
            .addStatement("$T typeNode = rootNode.get($S)", JsonNode.class, memberVariableName)
            .beginControlFlow("if (typeNode == null)")
            .addStatement("$T javaType = $L.constructType($T.class)", JavaType.class, DESERIALIZATION_CONTEXT_PARAMETER_NAME, enumTypeElement)
            .addStatement("throw new $T($L, \"$L not present\", javaType, null)", InvalidTypeIdException.class, JSON_PARSER_PARAMETER_NAME, memberVariableName)
            .endControlFlow()
            .addStatement("$T type = codec.treeToValue(typeNode, $T.$L)", enumTypeElement, enumTypeElement, "class")
            .beginControlFlow("switch (type)");

    enumValueElements.forEach(enumValueElement -> deserializeMethodBuilder
            .beginControlFlow("case $L:", enumValueElement)
            .addStatement("return codec.treeToValue(rootNode, $T.$L.$L)", enumTypeElement, enumValueElement, enumInstanceAccessorMethod)
            .endControlFlow());

    return deserializeMethodBuilder.beginControlFlow("default :")
            .addStatement("return null")
            .endControlFlow()
            .endControlFlow()
            .build();
}
 
开发者ID:peckb1,项目名称:autojackson,代码行数:36,代码来源:ComplexDeserializerCreator.java

示例14: responseBodyConverter

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
                                                        Retrofit retrofit) {
    JavaType javaType = mapper.getTypeFactory().constructType(type);
    ObjectReader reader = mapper.readerFor(javaType);
    return new JacksonResponseBodyConverter<>(reader, type);
}
 
开发者ID:sinhaDroid,项目名称:BlogBookApp,代码行数:8,代码来源:JacksonConverterFactory.java

示例15: findJavaType

import com.fasterxml.jackson.databind.JavaType; //导入依赖的package包/类
public static JavaType findJavaType(ClassLoader classLoader, String packageName, Swagger swagger, Object def) {
  if (def == null) {
    return VOID_JAVA_TYPE;
  }
  Converter converter = converterMap.get(def.getClass());
  if (converter == null) {
    throw new Error("not support def type: " + def.getClass());
  }

  return converter.convert(classLoader, packageName, swagger, def);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:12,代码来源:ConverterMgr.java


注:本文中的com.fasterxml.jackson.databind.JavaType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。