本文整理汇总了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;
}
示例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();
}
示例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)));
}
}
示例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);
}
}
示例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);
}
示例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);
}
}));
}
示例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);
}
示例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);
}
}
示例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());
}
示例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;
}
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}