Java 类com.fasterxml.jackson.annotation.JsonSubTypes 实例源码

项目:org.ops4j.ramler    文件:PojoGeneratingApiVisitor.java   
private void addJsonTypeInfo(JDefinedClass klass, ObjectTypeDeclaration type) {
    if (!context.getConfig().isJacksonTypeInfo()) {
        return;
    }
    if (type.discriminator() == null) {
        return;
    }
    List<String> derivedTypes = context.getApiModel().findDerivedTypes(type.name());
    if (derivedTypes.isEmpty()) {
        return;
    }
    JAnnotationUse typeInfo = klass.annotate(JsonTypeInfo.class);
    typeInfo.param("use", Id.NAME);
    typeInfo.param("include", As.EXISTING_PROPERTY);
    typeInfo.param("property", type.discriminator());

    JAnnotationUse subTypes = klass.annotate(JsonSubTypes.class);
    JAnnotationArrayMember typeArray = subTypes.paramArray(VALUE);

    for (String derivedType : derivedTypes) {
        JDefinedClass subtype = pkg._getClass(derivedType);
        typeArray.annotate(Type.class).param(VALUE, subtype);
    }
}
项目:jacksonatic    文件:TypeNameAutoAssigner.java   
public void assignTypeNameIfNecessary(ClassesMapping classesMapping, ClassMappingInternal<Object> currentClassMapping) {
    if (!currentClassMapping.hasAnnotation(JsonTypeName.class)) {
        typesWithPolymorphism.stream()
                .filter(typeWithPolymorphism -> typeWithPolymorphism.isAssignableFrom(currentClassMapping.getType()))
                .findFirst()
                .ifPresent(typeWithPolymorphism -> classesMapping.getOpt(typeWithPolymorphism)
                        .ifPresent(classMapping -> classMapping.getAnnotationOpt(JsonSubTypes.class)
                                .ifPresent((jsonSubTypes) -> Arrays.asList(jsonSubTypes.value()).stream()
                                        .filter(subtype -> subtype.value().equals(classMapping.getType()))
                                        .findFirst()
                                        .map(JsonSubTypes.Type::name)
                                        .ifPresent(classMapping::typeName)
                                )
                        )
                );
    }
}
项目:Lyrics    文件:JacksonStyle.java   
@Override
public void processSubTypeRule(TypeSpec.Builder typeSpec, TypeModel typeModel) {
    SubTypeModel subTypeModel = typeModel.getSubTypes();

    AnnotationSpec typeInfoAnnotation = AnnotationSpec.builder(JsonTypeInfo.class)
            .addMember("use", "$L", "JsonTypeInfo.Id.NAME")
            .addMember("include", "$L", "JsonTypeInfo.As." + (subTypeModel.isExistingProperty() ? "EXISTING_PROPERTY" : "PROPERTY"))
            .addMember("property", "$S", subTypeModel.getProperty())
            .build();

    AnnotationSpec.Builder subTypesBuilder = AnnotationSpec.builder(JsonSubTypes.class);
    for (Map.Entry<String, String> subType : subTypeModel.getSubTypeMapping().entrySet()) {
        subTypesBuilder.addMember("value", "$L",
                AnnotationSpec.builder(JsonSubTypes.Type.class)
                        .addMember("value", "$T.class", getClassName(subType.getValue()))
                        .addMember("name", "$S", subType.getKey())
                        .build());
    }

    typeSpec.addAnnotation(typeInfoAnnotation);
    typeSpec.addAnnotation(subTypesBuilder.build());
}
项目:haven-platform    文件:NodeMapping.java   
@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;
}
项目:teavm-flavour    文件:ClassInformationProvider.java   
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 = "";
        }
    }
}
项目:mandrel    文件:SchemaGenerator.java   
protected void getSchema(Class<?> clazz, ObjectNode schema, ArrayNode form) throws JsonMappingException {

        SchemaFactoryWrapper factoryWrapper = new SchemaFactoryWrapper();

        JsonSubTypes subtype = clazz.getAnnotation(JsonSubTypes.class);
        if (subtype != null) {
            doForSubtype(factoryWrapper, schema, form, subtype);
        } else {
            objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(clazz), factoryWrapper);
            JsonSchema jsonSchema = factoryWrapper.finalSchema();
            jsonSchema.setId(null);
            String title = clazz.getSimpleName().replaceAll("\\.", "_");
            jsonSchema.asObjectSchema().setTitle(title);

            iterateOnProperties(jsonSchema.asObjectSchema().getProperties());
            schema.putPOJO(title, jsonSchema);
        }
    }
项目:gwt-jackson    文件:BeanProcessor.java   
private static ImmutableMap<JClassType, String> extractMetadata( TreeLogger logger, RebindConfiguration configuration, JClassType
        type, Optional<JsonTypeInfo> jsonTypeInfo, Optional<JsonSubTypes> propertySubTypes, Optional<JsonSubTypes> typeSubTypes,
                                                                 ImmutableList<JClassType> allSubtypes ) throws
        UnableToCompleteException {

    ImmutableMap.Builder<JClassType, String> classToMetadata = ImmutableMap.builder();

    classToMetadata.put( type, extractTypeMetadata( logger, configuration, type, type, jsonTypeInfo
            .get(), propertySubTypes, typeSubTypes, allSubtypes ) );

    for ( JClassType subtype : allSubtypes ) {
        classToMetadata.put( subtype, extractTypeMetadata( logger, configuration, type, subtype, jsonTypeInfo
                .get(), propertySubTypes, typeSubTypes, allSubtypes ) );
    }
    return classToMetadata.build();
}
项目:GitHub    文件:_AbstractResponse.java   
@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();
项目:GitHub    文件:CustomBuilderDeserialize.java   
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
@JsonSubTypes({
    @Type(name = "I", value = Integer.class),
    @Type(name = "O", value = Double.class)
})
// the annotation will be copied to a builder setter
public abstract @Nullable Object value();
项目:web3j    文件:WalletFile.java   
@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;
}
项目:jacksonatic    文件:ClassMappingInternal.java   
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()])));
}
项目:haven-platform    文件:NodeMapping.java   
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;
}
项目:spring-auto-restdocs    文件:TypeUtil.java   
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;
}
项目:yona-server    文件:JsonRootRelProvider.java   
private Class<?> determineBaseType(Class<?> type)
{
    Class<?> baseType = type;
    while ((baseType = baseType.getSuperclass()) != null)
    {
        JsonSubTypes subtypesAnnotation = getAnnotationByType(baseType, JsonSubTypes.class);
        if (containsType(subtypesAnnotation, type))
        {
            return baseType;
        }
    }
    return type;
}
项目:QuizUpWinner    文件:JacksonAnnotationIntrospector.java   
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;
}
项目:mandrel    文件:SchemaGenerator.java   
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))));
}
项目:typescript-generator    文件:Jackson2Parser.java   
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;
}
项目:typescript-generator    文件:Jackson2Parser.java   
private static JsonSubTypes.Type getJsonSubTypeForClass(JsonSubTypes types, Class<?> cls) {
    for (JsonSubTypes.Type type : types.value()) {
        if (type.value().equals(cls)) {
            return type;
        }
    }
    return null;
}
项目:stampede    文件:Backend.java   
@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();
}
项目:gwt-jackson    文件:PropertyProcessor.java   
private static void processBeanAnnotation( TreeLogger logger, JacksonTypeOracle typeOracle, RebindConfiguration configuration, JType
        type, PropertyAccessors propertyAccessors, PropertyInfoBuilder builder ) throws UnableToCompleteException {

    // identity
    Optional<JsonIdentityInfo> jsonIdentityInfo = propertyAccessors.getAnnotation( JsonIdentityInfo.class );
    Optional<JsonIdentityReference> jsonIdentityReference = propertyAccessors.getAnnotation( JsonIdentityReference.class );

    // type info
    Optional<JsonTypeInfo> jsonTypeInfo = propertyAccessors.getAnnotation( JsonTypeInfo.class );
    Optional<JsonSubTypes> propertySubTypes = propertyAccessors.getAnnotation( JsonSubTypes.class );

    // if no annotation is present that overrides bean processing, we just stop now
    if ( !jsonIdentityInfo.isPresent() && !jsonIdentityReference.isPresent() && !jsonTypeInfo.isPresent() && !propertySubTypes
            .isPresent() ) {
        // no override on field
        return;
    }

    // we need to find the bean to apply annotation on
    Optional<JClassType> beanType = extractBeanType( logger, typeOracle, type, builder.getPropertyName() );

    if ( beanType.isPresent() ) {
        if ( jsonIdentityInfo.isPresent() || jsonIdentityReference.isPresent() ) {
            builder.setIdentityInfo( BeanProcessor.processIdentity( logger, typeOracle, configuration, beanType
                    .get(), jsonIdentityInfo, jsonIdentityReference ) );
        }

        if ( jsonTypeInfo.isPresent() || propertySubTypes.isPresent() ) {
            builder.setTypeInfo( BeanProcessor.processType( logger, typeOracle, configuration, beanType
                    .get(), jsonTypeInfo, propertySubTypes ) );
        }
    } else {
        logger.log( Type.WARN, "Annotation present on property " + builder.getPropertyName() + " but no valid bean has been found." );
    }
}
项目:gwt-jackson    文件:BeanProcessor.java   
/**
 * <p>processType</p>
 *
 * @param logger a {@link com.google.gwt.core.ext.TreeLogger} object.
 * @param typeOracle a {@link com.github.nmorel.gwtjackson.rebind.JacksonTypeOracle} object.
 * @param configuration a {@link com.github.nmorel.gwtjackson.rebind.RebindConfiguration} object.
 * @param typeOracle a {@link com.github.nmorel.gwtjackson.rebind.JacksonTypeOracle} object.
 * @param type a {@link com.google.gwt.core.ext.typeinfo.JClassType} object.
 * @param jsonTypeInfo a {@link com.google.gwt.thirdparty.guava.common.base.Optional} object.
 * @param propertySubTypes a {@link com.google.gwt.thirdparty.guava.common.base.Optional} object.
 * @return a {@link com.google.gwt.thirdparty.guava.common.base.Optional} object.
 * @throws com.google.gwt.core.ext.UnableToCompleteException if any.
 */
public static Optional<BeanTypeInfo> processType( TreeLogger logger, JacksonTypeOracle typeOracle, RebindConfiguration configuration,
                                                  JClassType type, Optional<JsonTypeInfo> jsonTypeInfo, Optional<JsonSubTypes>
        propertySubTypes ) throws UnableToCompleteException {

    if ( !jsonTypeInfo.isPresent() ) {
        jsonTypeInfo = findFirstEncounteredAnnotationsOnAllHierarchy( configuration, type, JsonTypeInfo.class );
        if ( !jsonTypeInfo.isPresent() ) {
            return Optional.absent();
        }
    }

    Id use = jsonTypeInfo.get().use();
    As include = jsonTypeInfo.get().include();
    String propertyName = jsonTypeInfo.get().property().isEmpty() ? jsonTypeInfo.get().use().getDefaultPropertyName() : jsonTypeInfo
            .get().property();

    Optional<JsonSubTypes> typeSubTypes = findFirstEncounteredAnnotationsOnAllHierarchy( configuration, type, JsonSubTypes.class );

    // TODO we could do better, we actually extract metadata twice for a lot of classes
    ImmutableMap<JClassType, String> classToSerializationMetadata = extractMetadata( logger, configuration, type, jsonTypeInfo,
            propertySubTypes, typeSubTypes, CreatorUtils
                    .filterSubtypesForSerialization( logger, configuration, type ) );
    ImmutableMap<JClassType, String> classToDeserializationMetadata = extractMetadata( logger, configuration, type, jsonTypeInfo,
            propertySubTypes, typeSubTypes, CreatorUtils
                    .filterSubtypesForDeserialization( logger, configuration, type ) );

    return Optional.of(
            new BeanTypeInfo( use, include, propertyName, classToSerializationMetadata, classToDeserializationMetadata ) );
}
项目:gwt-jackson    文件:BeanProcessor.java   
private static String extractTypeMetadata( TreeLogger logger, RebindConfiguration configuration, JClassType baseType, JClassType
        subtype, JsonTypeInfo typeInfo, Optional<JsonSubTypes> propertySubTypes, Optional<JsonSubTypes> baseSubTypes,
                                           ImmutableList<JClassType> allSubtypes ) throws UnableToCompleteException {
    switch ( typeInfo.use() ) {
        case NAME:
            // we first look the name on JsonSubTypes annotations. Top ones override the bottom ones.
            String name = findNameOnJsonSubTypes( baseType, subtype, allSubtypes, propertySubTypes, baseSubTypes );
            if ( null != name && !"".equals( name ) ) {
                return name;
            }

            // we look if the name is defined on the type with JsonTypeName
            Optional<JsonTypeName> typeName = findFirstEncounteredAnnotationsOnAllHierarchy( configuration, subtype, JsonTypeName
                    .class );
            if ( typeName.isPresent() && !Strings.isNullOrEmpty( typeName.get().value() ) ) {
                return typeName.get().value();
            }

            // we use the default name (ie simple name of the class)
            String simpleBinaryName = subtype.getQualifiedBinaryName();
            int indexLastDot = simpleBinaryName.lastIndexOf( '.' );
            if ( indexLastDot != -1 ) {
                simpleBinaryName = simpleBinaryName.substring( indexLastDot + 1 );
            }
            return simpleBinaryName;
        case MINIMAL_CLASS:
            if ( !baseType.getPackage().isDefault() ) {
                String basePackage = baseType.getPackage().getName();
                if ( subtype.getQualifiedBinaryName().startsWith( basePackage + "." ) ) {
                    return subtype.getQualifiedBinaryName().substring( basePackage.length() );
                }
            }
        case CLASS:
            return subtype.getQualifiedBinaryName();
        default:
            logger.log( TreeLogger.Type.ERROR, "JsonTypeInfo.Id." + typeInfo.use() + " is not supported" );
            throw new UnableToCompleteException();
    }
}
项目:gwt-jackson    文件:BeanProcessor.java   
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;
}
项目:gwt-jackson    文件:BeanProcessor.java   
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;
}
项目:javersion    文件:JacksonMappingResolver.java   
@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();
}
项目:immutables    文件:_AbstractResponse.java   
@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();
项目:immutables    文件:CustomBuilderDeserialize.java   
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
@JsonSubTypes({
    @Type(name = "I", value = Integer.class),
    @Type(name = "O", value = Double.class)
})
// the annotation will be copied to a builder setter
public abstract @Nullable Object value();
项目:camunda-bpm-platform    文件:FilterDto.java   
@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;
}
项目:cf2pojo    文件:GenerateTask.java   
@TaskAction
void generateJavaClasses() throws IOException, ClassNotFoundException {
    if (!inputDir.isDirectory()) {
        throw new RuntimeException("inputDir needs to be a directory");
    }

    CompilationUnit baseResourceCompilationUnit = JavaParser.parseResource("ResourceBase.java");
    ClassOrInterfaceDeclaration baseResourceClass = baseResourceCompilationUnit.getClassByName("ResourceBase")
        .orElseThrow(() -> new RuntimeException("Could not find ResourceBase class"));

    // Add an @JsonSubTypes annotation to the ResourceBase class
    ArrayInitializerExpr jsonSubTypesArrayExpr = new ArrayInitializerExpr();
    SingleMemberAnnotationExpr jsonSubTypesAnnotation = new SingleMemberAnnotationExpr(
        new Name(JsonSubTypes.class.getSimpleName()), jsonSubTypesArrayExpr);
    baseResourceClass.addAnnotation(jsonSubTypesAnnotation);
    baseResourceCompilationUnit.addImport(JsonSubTypes.class);

    File[] inputFiles = inputDir.listFiles((dir, name) -> name.endsWith("Specification.json"));
    if (inputFiles == null || inputFiles.length == 0) {
        throw new RuntimeException(String.format("Did not find any spec files in directory %s",
            inputDir.getName()));
    }

    ObjectMapper objectMapper = new ObjectMapper();
    for (File inputFile : inputFiles) {

        // Deserialize specification from JSON file
        CloudFormationSpecification spec;
        try (FileInputStream inputStream = new FileInputStream(inputFile)) {
            spec = objectMapper.readValue(inputStream, CloudFormationSpecification.class);
        } catch (JsonProcessingException e) {
            LOGGER.info("Error deserializing file: {}.  Skipping...", inputFile.getName());
            continue;
        }

        // Generate the compilation unit from the specification
        CompilationUnit resourceCompilationUnit = generateCompilationUnitFromCloudFormationSpec(spec,
            jsonSubTypesArrayExpr);

        // Write the compilation unit out to a file
        String resourceClassName = resourceCompilationUnit.getType(0).getNameAsString();
        File resourceClassFile = new File(generatedFileDir, resourceClassName + ".java");
        writeFile(resourceClassFile, resourceCompilationUnit.toString());
    }

    // Write ResourceBase.java file
    writeFile(new File(generatedFileDir, "ResourceBase.java"), baseResourceCompilationUnit.toString(
        new CustomPrettyPrinterConfiguration().setArrayLiteralMembersOnSeparateLines(true)));

    // Copy over static files like ValueType.java without modification
    for (String fileName : STATIC_FILES) {
        InputStream stream = getClass().getClassLoader().getResourceAsStream(fileName);
        Files.copy(stream, new File(generatedFileDir, fileName).toPath());
        stream.close();
    }
}
项目:jacksonatic    文件:JacksonaticJsonSubTypesType.java   
@Override
public Class<? extends Annotation> annotationType() {
    return JsonSubTypes.Type.class;
}
项目:jacksonatic    文件:JacksonaticJsonSubTypesType.java   
@Override
public  JsonSubTypes.Type build() {
    return type;
}
项目:jacksonatic    文件:JacksonaticJsonSubTypes.java   
@Override
public Class<? extends Annotation> annotationType() {
    return JsonSubTypes.class;
}
项目:jacksonatic    文件:JacksonaticJsonSubTypes.java   
@Override
public JsonSubTypes build() {
    return jsonSubTypes;
}
项目:jacksonatic    文件:TypeNameAutoAssigner.java   
public void saveTypeWithJsonSubTypes(ClassMappingInternal<Object> currentClassMapping) {
    if (currentClassMapping.hasAnnotation(JsonSubTypes.class)) {
        typesWithPolymorphism.add(currentClassMapping.getType());
    }
}
项目:yona-server    文件:JsonRootRelProvider.java   
private boolean containsType(JsonSubTypes subtypesAnnotation, Class<?> type)
{
    return (subtypesAnnotation != null)
            && (Arrays.asList(subtypesAnnotation.value()).stream().anyMatch(t -> t.value() == type));
}
项目:gwt-jackson    文件:BeanProcessor.java   
private static Optional<BeanTypeInfo> processType( TreeLogger logger, JacksonTypeOracle typeOracle, RebindConfiguration
        configuration, JClassType type ) throws UnableToCompleteException {
    return processType( logger, typeOracle, configuration, type, Optional.<JsonTypeInfo>absent(), Optional.<JsonSubTypes>absent() );
}
项目:atlas-deer    文件:Id.java   
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
@JsonSubTypes.Type(value = Long.class)
public long longValue() {
    return longValue;
}