Java Code Examples for com.fasterxml.jackson.annotation.JsonSubTypes#Type
The following examples show how to use
com.fasterxml.jackson.annotation.JsonSubTypes#Type .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeMapping.java From haven-platform with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: ContestModuleDump.java From judgels with GNU General Public License v2.0 | 6 votes |
@Nullable @Value.Default @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "name", visible = true, defaultImpl = NoClass.class ) @JsonSubTypes({ @JsonSubTypes.Type(value = ImmutableScoreboardModuleConfig.class), @JsonSubTypes.Type(value = ImmutableClarificationTimeLimitModuleConfig.class), @JsonSubTypes.Type(value = ImmutableFrozenScoreboardModuleConfig.class), @JsonSubTypes.Type(value = ImmutableVirtualModuleConfig.class) }) public ModuleConfig getConfig() { return null; }
Example 3
Source File: KeyStoreFile.java From BlockchainWallet-Crypto with GNU General Public License v3.0 | 5 votes |
@JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "kdf") @JsonSubTypes({ @JsonSubTypes.Type(value = Aes128CtrKdfParams.class, name = KeyStore.AES_128_CTR), @JsonSubTypes.Type(value = ScryptKdfParams.class, name = KeyStore.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; }
Example 4
Source File: _AbstractResponse.java From immutables with Apache License 2.0 | 5 votes |
@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();
Example 5
Source File: JobConfiguration.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * The sub type names refer to the {@link JobType} enumeration. Defaults to null for unmapped job types. */ @JacksonXmlProperty @JsonProperty @Property( required = FALSE ) @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "jobType", defaultImpl = java.lang.Void.class ) @JsonSubTypes( value = { @JsonSubTypes.Type( value = AnalyticsJobParameters.class, name = "ANALYTICS_TABLE" ), @JsonSubTypes.Type( value = ContinuousAnalyticsJobParameters.class, name = "CONTINUOUS_ANALYTICS_TABLE" ), @JsonSubTypes.Type( value = MonitoringJobParameters.class, name = "MONITORING" ), @JsonSubTypes.Type( value = PredictorJobParameters.class, name = "PREDICTOR" ), @JsonSubTypes.Type( value = PushAnalysisJobParameters.class, name = "PUSH_ANALYSIS" ), @JsonSubTypes.Type( value = SmsJobParameters.class, name = "SMS_SEND" ), @JsonSubTypes.Type( value = MetadataSyncJobParameters.class, name = "META_DATA_SYNC" ), @JsonSubTypes.Type( value = EventProgramsDataSynchronizationJobParameters.class, name = "EVENT_PROGRAMS_DATA_SYNC" ), @JsonSubTypes.Type( value = TrackerProgramsDataSynchronizationJobParameters.class, name = "TRACKER_PROGRAMS_DATA_SYNC" ), @JsonSubTypes.Type( value = DataSynchronizationJobParameters.class, name = "DATA_SYNC" ) } ) public JobParameters getJobParameters() { return jobParameters; }
Example 6
Source File: NodeMapping.java From haven-platform with Apache License 2.0 | 5 votes |
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; }
Example 7
Source File: TypeGuardsForJackson2PolymorphismExtension.java From typescript-generator with MIT License | 5 votes |
@Override public void emitElements(Writer writer, Settings settings, boolean exportKeyword, TsModel model) { for (TsBeanModel tsBean : model.getBeans()) { final Class<?> beanClass = tsBean.getOrigin(); if (beanClass != null) { final JsonSubTypes jsonSubTypes = beanClass.getAnnotation(JsonSubTypes.class); final JsonTypeInfo jsonTypeInfo = beanClass.getAnnotation(JsonTypeInfo.class); if (jsonSubTypes != null && jsonTypeInfo != null && jsonTypeInfo.include() == JsonTypeInfo.As.PROPERTY) { final String propertyName = jsonTypeInfo.property(); for (JsonSubTypes.Type subType : jsonSubTypes.value()) { String propertyValue = null; if (jsonTypeInfo.use() == JsonTypeInfo.Id.NAME) { if (subType.name().equals("")) { final JsonTypeName jsonTypeName = subType.value().getAnnotation(JsonTypeName.class); if (jsonTypeName != null) { propertyValue = jsonTypeName.value(); } } else { propertyValue = subType.name(); } } if (propertyValue != null) { final String baseTypeName = tsBean.getName().getSimpleName(); final String subTypeName = findTypeName(subType.value(), model); if (baseTypeName != null && subTypeName != null) { writer.writeIndentedLine(""); emitTypeGuard(writer, settings, exportKeyword, baseTypeName, subTypeName, propertyName, propertyValue); } } } } } } }
Example 8
Source File: Property.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
static Map<Class<?>, String> subtypeMap(Class<?> crdClass) { JsonSubTypes subtypes = crdClass.getAnnotation(JsonSubTypes.class); if (subtypes != null) { LinkedHashMap<Class<?>, String> result = new LinkedHashMap<>(subtypes.value().length); for (JsonSubTypes.Type type : subtypes.value()) { result.put(type.value(), type.name()); } return result; } else { return emptyMap(); } }
Example 9
Source File: WalletFile.java From web3j with Apache License 2.0 | 5 votes |
@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; }
Example 10
Source File: FilterDto.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@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; }
Example 11
Source File: WalletFile.java From blockchain with Apache License 2.0 | 5 votes |
@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; }
Example 12
Source File: BeanProcessor.java From gwt-jackson with Apache License 2.0 | 5 votes |
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; }
Example 13
Source File: BeanProcessor.java From gwt-jackson with Apache License 2.0 | 5 votes |
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; }
Example 14
Source File: Item.java From judgels with GNU General Public License v2.0 | 5 votes |
@JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type", visible = true ) @JsonSubTypes({ @JsonSubTypes.Type(value = ImmutableStatementItemConfig.class), @JsonSubTypes.Type(value = ImmutableMultipleChoiceItemConfig.class), @JsonSubTypes.Type(value = ImmutableShortAnswerItemConfig.class), @JsonSubTypes.Type(value = ImmutableEssayItemConfig.class) }) ItemConfig getConfig();
Example 15
Source File: ContestStyleDump.java From judgels with GNU General Public License v2.0 | 5 votes |
@JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "name", visible = true ) @JsonSubTypes({ @JsonSubTypes.Type(value = ImmutableIoiStyleModuleConfig.class), @JsonSubTypes.Type(value = ImmutableIcpcStyleModuleConfig.class), @JsonSubTypes.Type(value = ImmutableGcjStyleModuleConfig.class), @JsonSubTypes.Type(value = ImmutableBundleStyleModuleConfig.class) }) StyleModuleConfig getConfig();
Example 16
Source File: WalletFile.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
@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; }
Example 17
Source File: WalletFile.java From client-sdk-java with Apache License 2.0 | 5 votes |
@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; }
Example 18
Source File: JsonSubTypesResolverLookUpTest.java From jsonschema-generator with Apache License 2.0 | 5 votes |
@JsonSubTypes({ @JsonSubTypes.Type(TestSubClass2.class), @JsonSubTypes.Type(TestSubClass3.class) }) public TestSuperClassWithNameProperty getSupertypeWithAnnotationOnFieldAndGetter() { return this.supertypeWithAnnotationOnFieldAndGetter; }
Example 19
Source File: Channel.java From chromecast-java-api-v2 with Apache License 2.0 | 5 votes |
private boolean isAppEvent(JsonNode parsed) { if (parsed != null && parsed.has("responseType")) { String type = parsed.get("responseType").asText(); for (JsonSubTypes.Type t : STANDARD_RESPONSE_TYPES) { if (t.name().equals(type)) { return false; } } } return parsed == null || !parsed.has("requestId"); }
Example 20
Source File: Jackson2Parser.java From typescript-generator with MIT License | 4 votes |
private String getTypeName(JsonTypeInfo parentJsonTypeInfo, final Class<?> cls) { // Id.CLASS if (parentJsonTypeInfo.use() == JsonTypeInfo.Id.CLASS) { return cls.getName(); } // find custom name registered with `registerSubtypes` AnnotatedClass annotatedClass = AnnotatedClassResolver .resolveWithoutSuperTypes(objectMapper.getSerializationConfig(), cls); Collection<NamedType> subtypes = objectMapper.getSubtypeResolver() .collectAndResolveSubtypesByClass(objectMapper.getSerializationConfig(), annotatedClass); if (subtypes.size() == 1) { NamedType subtype = subtypes.iterator().next(); if (subtype.getName() != null) { return subtype.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; }