當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonSubTypes.Type方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.annotation.JsonSubTypes.Type方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonSubTypes.Type方法的具體用法?Java JsonSubTypes.Type怎麽用?Java JsonSubTypes.Type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.annotation.JsonSubTypes的用法示例。


在下文中一共展示了JsonSubTypes.Type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getPayload

import com.fasterxml.jackson.annotation.JsonSubTypes; //導入方法依賴的package包/類
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type")
@JsonSubTypes({
        @JsonSubTypes.Type(name = "one", value = PayloadOne.class),
  @JsonSubTypes.Type(name = "two", value = org.immutables.fixture.jackson.poly2.PayloadTwo.class)
})
@JsonProperty("payload")
public abstract Payload getPayload();
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:_AbstractResponse.java

示例4: setKdfparams

import com.fasterxml.jackson.annotation.JsonSubTypes; //導入方法依賴的package包/類
@JsonTypeInfo(
        use = JsonTypeInfo.Id.NAME,
        include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
        property = "kdf")
@JsonSubTypes({
        @JsonSubTypes.Type(value = Aes128CtrKdfParams.class, name = Wallet.AES_128_CTR),
        @JsonSubTypes.Type(value = ScryptKdfParams.class, name = Wallet.SCRYPT)
})
// To support my Ether Wallet keys uncomment this annotation & comment out the above
//  @JsonDeserialize(using = KdfParamsDeserialiser.class)
// Also add the following to the ObjectMapperFactory
// objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
public void setKdfparams(KdfParams kdfparams) {
    this.kdfparams = kdfparams;
}
 
開發者ID:web3j,項目名稱:web3j,代碼行數:16,代碼來源:WalletFile.java

示例5: addNamedSubType

import com.fasterxml.jackson.annotation.JsonSubTypes; //導入方法依賴的package包/類
public void addNamedSubType(Class<? extends T> subType, String name) {
    List<JsonSubTypes.Type> types = Optional.ofNullable(annotations.get(JsonSubTypes.class))
            .map(annotation -> new ArrayList<>(Arrays.asList(((JsonSubTypes) annotation).value())))
            .orElse(new ArrayList<>());
    types.add(JacksonaticJsonSubTypesType.type(name, subType).build());
    annotations.add(jsonSubTypes(types.toArray(new JsonSubTypes.Type[types.size()])));
}
 
開發者ID:mrenou,項目名稱:jacksonatic,代碼行數:8,代碼來源:ClassMappingInternal.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: getTypeName

import com.fasterxml.jackson.annotation.JsonSubTypes; //導入方法依賴的package包/類
private String getTypeName(JsonTypeInfo parentJsonTypeInfo, final Class<?> cls) {
    // Id.CLASS
    if (parentJsonTypeInfo.use() == JsonTypeInfo.Id.CLASS) {
        return cls.getName();
    }
    // find @JsonTypeName recursively
    final JsonTypeName jsonTypeName = getAnnotationRecursive(cls, JsonTypeName.class);
    if (jsonTypeName != null && !jsonTypeName.value().isEmpty()) {
        return jsonTypeName.value();
    }
    // find @JsonSubTypes.Type recursively
    final JsonSubTypes jsonSubTypes = getAnnotationRecursive(cls, JsonSubTypes.class, new Predicate<JsonSubTypes>() {
        @Override
        public boolean test(JsonSubTypes types) {
            return getJsonSubTypeForClass(types, cls) != null;
        }
    });
    if (jsonSubTypes != null) {
        final JsonSubTypes.Type jsonSubType = getJsonSubTypeForClass(jsonSubTypes, cls);
        if (!jsonSubType.name().isEmpty()) {
            return jsonSubType.name();
        }
    }
    // use simplified class name if it's not an interface or abstract
    if(!cls.isInterface() && !Modifier.isAbstract(cls.getModifiers())) {
        return cls.getName().substring(cls.getName().lastIndexOf(".") + 1);
    }
    return null;
}
 
開發者ID:vojtechhabarta,項目名稱:typescript-generator,代碼行數:30,代碼來源:Jackson2Parser.java

示例11: 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

示例12: getBackendImplementation

import com.fasterxml.jackson.annotation.JsonSubTypes; //導入方法依賴的package包/類
@NotNull
@Valid
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonSubTypes({
    @JsonSubTypes.Type(name = "postgres", value = Postgres.class),
    @JsonSubTypes.Type(name = "mysql", value = MySql.class)
    })
@JsonProperty(required = true)
public BackendImplementation getBackendImplementation() {
  return super.getBackendImplementation();
}
 
開發者ID:torodb,項目名稱:stampede,代碼行數:12,代碼來源:Backend.java

示例13: findNameOnJsonSubTypes

import com.fasterxml.jackson.annotation.JsonSubTypes; //導入方法依賴的package包/類
private static String findNameOnJsonSubTypes( JClassType baseType, JClassType subtype, ImmutableList<JClassType> allSubtypes,
                                              Optional<JsonSubTypes> propertySubTypes, Optional<JsonSubTypes> baseSubTypes ) {
    JsonSubTypes.Type typeFound = findTypeOnSubTypes( subtype, propertySubTypes );
    if ( null != typeFound ) {
        return typeFound.name();
    }

    typeFound = findTypeOnSubTypes( subtype, baseSubTypes );
    if ( null != typeFound ) {
        return typeFound.name();
    }

    if ( baseType != subtype ) {
        // we look in all the hierarchy
        JClassType type = subtype;
        while ( null != type ) {
            if ( allSubtypes.contains( type ) ) {
                JsonSubTypes.Type found = findTypeOnSubTypes( subtype, Optional.fromNullable( type
                        .getAnnotation( JsonSubTypes.class ) ) );
                if ( null != found ) {
                    typeFound = found;
                }
            }
            type = type.getSuperclass();
        }

        if ( null != typeFound ) {
            return typeFound.name();
        }
    }

    return null;
}
 
開發者ID:nmorel,項目名稱:gwt-jackson,代碼行數:34,代碼來源:BeanProcessor.java

示例14: findTypeOnSubTypes

import com.fasterxml.jackson.annotation.JsonSubTypes; //導入方法依賴的package包/類
private static JsonSubTypes.Type findTypeOnSubTypes( JClassType subtype, Optional<JsonSubTypes> jsonSubTypes ) {
    if ( jsonSubTypes.isPresent() ) {
        for ( JsonSubTypes.Type type : jsonSubTypes.get().value() ) {
            if ( type.value().getName().equals( subtype.getQualifiedBinaryName() ) ) {
                return type;
            }
        }
    }
    return null;
}
 
開發者ID:nmorel,項目名稱:gwt-jackson,代碼行數:11,代碼來源:BeanProcessor.java

示例15: setQuery

import com.fasterxml.jackson.annotation.JsonSubTypes; //導入方法依賴的package包/類
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
    property = "resourceType", defaultImpl=TaskQueryDto.class)
  @JsonSubTypes(value = {
  @JsonSubTypes.Type(value = TaskQueryDto.class, name = EntityTypes.TASK)})
public void setQuery(AbstractQueryDto<?> query) {
  this.query = query;
}
 
開發者ID:camunda,項目名稱:camunda-bpm-platform,代碼行數:8,代碼來源:FilterDto.java


注:本文中的com.fasterxml.jackson.annotation.JsonSubTypes.Type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。