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


Java JsonSubTypes.value方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.annotation.JsonSubTypes.value方法的典型用法代码示例。如果您正苦于以下问题:Java JsonSubTypes.value方法的具体用法?Java JsonSubTypes.value怎么用?Java JsonSubTypes.value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.annotation.JsonSubTypes的用法示例。


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

示例1: resolveJsonType

import com.fasterxml.jackson.annotation.JsonSubTypes; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <S> Class<S> resolveJsonType(String path, Class<S> type) {
    JsonTypeInfo typeInfo = AnnotationUtils.findAnnotation(type, JsonTypeInfo.class);
    if (typeInfo == null) {
        return null;
    }
    String property = getPropertyName(typeInfo);
    String proppath = KvUtils.join(path, property);
    try {
        KvNode node = getStorage().get(proppath);
        if(node == null) {
            return null;
        }
        String str = node.getValue();
        JsonSubTypes subTypes = AnnotationUtils.findAnnotation(type, JsonSubTypes.class);
        for (JsonSubTypes.Type t : subTypes.value()) {
            if (t.name().equals(str)) {
                return (Class<S>) t.value();
            }
        }
    } catch (Exception e) {
        log.error("can't instantiate class", e);
    }
    return null;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:26,代码来源:NodeMapping.java

示例2: getSubTypes

import com.fasterxml.jackson.annotation.JsonSubTypes; //导入方法依赖的package包/类
private void getSubTypes(ClassInformation information, ReflectClass<?> cls) {
    JsonSubTypes annot = cls.getAnnotation(JsonSubTypes.class);
    if (annot == null) {
        return;
    }

    for (JsonSubTypes.Type subtype : annot.value()) {
        Class<?> subclass = subtype.value();
        ClassInformation subtypeInformation = get(subclass.getName());
        if (subtypeInformation == null) {
            continue;
        }
        information.inheritance.subTypes.add(subtypeInformation);
        // TODO check whether name conflicts with one got from JsonTypeName
        if (!subtype.name().isEmpty()) {
            subtypeInformation.typeName = subtype.name();
        }
        if (subtypeInformation.typeName == null) {
            subtypeInformation.typeName = "";
        }
    }
}
 
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:23,代码来源:ClassInformationProvider.java

示例3: getJsonType

import com.fasterxml.jackson.annotation.JsonSubTypes; //导入方法依赖的package包/类
private String getJsonType(Class<?> clazz, JsonTypeInfo typeInfo) {
    String value;
    JsonTypeInfo.Id use = typeInfo.use();
    switch (use) {
        case CLASS:
            value = clazz.getName();
            break;
        case NAME: {
            JsonSubTypes.Type needed = null;
            JsonSubTypes subTypes = AnnotationUtils.findAnnotation(clazz, JsonSubTypes.class);
            if(subTypes != null) {
                for(JsonSubTypes.Type type: subTypes.value()) {
                    if(type.value().equals(clazz)) {
                        needed = type;
                        break;
                    }
                }
            }
            if(needed == null) {
                throw new IllegalArgumentException("On " + clazz + " can not find 'JsonSubTypes' record for current type.");
            }
            value = needed.name();
            break;
        }
        default:
            throw new IllegalArgumentException("On " + clazz + " find unexpected 'JsonTypeInfo.use' value: " + use);
    }
    return value;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:30,代码来源:NodeMapping.java

示例4: resolveNonArrayTypes

import com.fasterxml.jackson.annotation.JsonSubTypes; //导入方法依赖的package包/类
private static List<JavaType> resolveNonArrayTypes(JavaType javaType, TypeFactory typeFactory) {
    List<JavaType> types = new ArrayList<>();
    types.add(javaType);

    Class<?> rawClass = javaType.getRawClass();
    JsonSubTypes jsonSubTypes = rawClass.getAnnotation(JsonSubTypes.class);
    if (jsonSubTypes != null) {
        for (JsonSubTypes.Type subType : jsonSubTypes.value()) {
            JavaType javaSubType = typeFactory.constructType(subType.value());
            types.add(javaSubType);
        }
    }

    return types;
}
 
开发者ID:ScaCap,项目名称:spring-auto-restdocs,代码行数:16,代码来源:TypeUtil.java

示例5: findSubtypes

import com.fasterxml.jackson.annotation.JsonSubTypes; //导入方法依赖的package包/类
public List<NamedType> findSubtypes(Annotated paramAnnotated)
{
  JsonSubTypes localJsonSubTypes = (JsonSubTypes)paramAnnotated.getAnnotation(JsonSubTypes.class);
  if (localJsonSubTypes == null)
    return null;
  JsonSubTypes.Type[] arrayOfType = localJsonSubTypes.value();
  ArrayList localArrayList = new ArrayList(arrayOfType.length);
  int i = arrayOfType.length;
  for (int j = 0; j < i; j++)
  {
    JsonSubTypes.Type localType = arrayOfType[j];
    localArrayList.add(new NamedType(localType.value(), localType.name()));
  }
  return localArrayList;
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:16,代码来源:JacksonAnnotationIntrospector.java

示例6: doForSubtype

import com.fasterxml.jackson.annotation.JsonSubTypes; //导入方法依赖的package包/类
public void doForSubtype(SchemaFactoryWrapper factoryWrapper, ObjectNode schema, ArrayNode form, JsonSubTypes subtype) throws JsonMappingException {
	List<String> types = new ArrayList<>();
	for (JsonSubTypes.Type type : subtype.value()) {
		objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(type.value()), factoryWrapper);
		JsonSchema jsonSchema = factoryWrapper.finalSchema();
		jsonSchema.setId(null);
		String title = type.name().replaceAll("\\.", "_");
		jsonSchema.asObjectSchema().setTitle(title);

		iterateOnProperties(jsonSchema.asObjectSchema().getProperties());
		schema.putPOJO(title, jsonSchema);
		types.add(title);
	}

	ObjectNode choice = objectMapper.createObjectNode();
	choice.put("type", "string");
	choice.putPOJO("enum", types);
	schema.set("choice", choice);

	form.addPOJO(objectMapper
			.createObjectNode()
			.put("type", "fieldset")
			.put("title", "Sources")
			.set("items",
					objectMapper.createArrayNode().add(
							objectMapper.createObjectNode().put("type", "selectfieldset").put("key", "choice").put("title", "Choose a source")
									.putPOJO("items", types))));
}
 
开发者ID:Treydone,项目名称:mandrel,代码行数:29,代码来源:SchemaGenerator.java

示例7: getJsonSubTypeForClass

import com.fasterxml.jackson.annotation.JsonSubTypes; //导入方法依赖的package包/类
private static JsonSubTypes.Type getJsonSubTypeForClass(JsonSubTypes types, Class<?> cls) {
    for (JsonSubTypes.Type type : types.value()) {
        if (type.value().equals(cls)) {
            return type;
        }
    }
    return null;
}
 
开发者ID:vojtechhabarta,项目名称:typescript-generator,代码行数:9,代码来源:Jackson2Parser.java

示例8: subclasses

import com.fasterxml.jackson.annotation.JsonSubTypes; //导入方法依赖的package包/类
@Nonnull
@Override
public Result<Map<TypeDescriptor, String>> subclasses(TypeDescriptor type) {
    JsonSubTypes jsonSubType = type.getAnnotation(JsonSubTypes.class);
    if (jsonSubType != null && jsonSubType.value().length > 0) {
        TypeDescriptors typeDescriptors = type.getTypeDescriptors();
        Map<TypeDescriptor, String> aliasesByTypes = asList(jsonSubType.value()).stream()
                .collect(toMap(subType -> typeDescriptors.get(subType.value()), Type::name));
        return Result.of(aliasesByTypes);
    }
    return Result.notFound();
}
 
开发者ID:ssaarela,项目名称:javersion,代码行数:13,代码来源:JacksonMappingResolver.java


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