當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。