@Override public List<? extends Module> getJacksonModules() { return Collections.singletonList( new SimpleModule("ParquetInputRowParserModule") .registerSubtypes( new NamedType(ParquetAvroHadoopInputRowParser.class, PARQUET_AVRO_INPUT_PARSER_TYPE), new NamedType(ParquetHadoopInputRowParser.class, PARQUET_SIMPLE_INPUT_PARSER_TYPE), new NamedType(ParquetParseSpec.class, PARQUET_SIMPLE_INPUT_PARSER_TYPE) ) ); }
Class<?> cls = t.getType(); String id = t.hasName() ? t.getName() : _defaultTypeId(cls); if (forSer) { typeToId.put(cls.getName(), id); if (cls.isAssignableFrom(prev.getRawClass())) { // nope, more generic (or same) continue; idToType.put(id, config.constructType(cls));
/** * Method called to find subtypes for a specific type (class), using * type id as the unique key (in case of conflicts). */ protected void _collectAndResolveByTypeId(AnnotatedClass annotatedType, NamedType namedType, MapperConfig<?> config, Set<Class<?>> typesHandled, Map<String,NamedType> byName) { final AnnotationIntrospector ai = config.getAnnotationIntrospector(); if (!namedType.hasName()) { String name = ai.findTypeName(annotatedType); if (name != null) { namedType = new NamedType(namedType.getType(), name); } } if (namedType.hasName()) { byName.put(namedType.getName(), namedType); } // only check subtypes if this type hadn't yet been handled if (typesHandled.add(namedType.getType())) { Collection<NamedType> st = ai.findSubtypes(annotatedType); if (st != null && !st.isEmpty()) { for (NamedType subtype : st) { AnnotatedClass subtypeClass = AnnotatedClassResolver.resolveWithoutSuperTypes(config, subtype.getType()); _collectAndResolveByTypeId(subtypeClass, subtype, config, typesHandled, byName); } } } }
/** * Helper method used for merging explicitly named types and handled classes * without explicit names. */ protected Collection<NamedType> _combineNamedAndUnnamed(Class<?> rawBase, Set<Class<?>> typesHandled, Map<String,NamedType> byName) { ArrayList<NamedType> result = new ArrayList<NamedType>(byName.values()); // Ok, so... we will figure out which classes have no explicitly assigned name, // by removing Classes from Set. And for remaining classes, add an anonymous // marker for (NamedType t : byName.values()) { typesHandled.remove(t.getType()); } for (Class<?> cls : typesHandled) { // 27-Apr-2017, tatu: [databind#1616] Do not add base type itself unless // it is concrete (or has explicit type name) if ((cls == rawBase) && Modifier.isAbstract(cls.getModifiers())) { continue; } result.add(new NamedType(cls)); } return result; } }
@Override public List<? extends Module> getJacksonModules() { return Collections.singletonList( new SimpleModule("HllSketchModule").registerSubtypes( new NamedType(HllSketchMergeAggregatorFactory.class, MERGE_TYPE_NAME), new NamedType(HllSketchBuildAggregatorFactory.class, BUILD_TYPE_NAME), new NamedType(HllSketchMergeAggregatorFactory.class, TYPE_NAME), new NamedType(HllSketchToStringPostAggregator.class, TO_STRING_TYPE_NAME), new NamedType(HllSketchUnionPostAggregator.class, UNION_TYPE_NAME), new NamedType(HllSketchToEstimateWithBoundsPostAggregator.class, ESTIMATE_WITH_BOUNDS_TYPE_NAME) ).addSerializer(HllSketch.class, new HllSketchJsonSerializer()) ); }
AnnotatedMember property, JavaType baseType) final AnnotationIntrospector ai = config.getAnnotationIntrospector(); Class<?> rawBase = (baseType == null) ? property.getRawType() : baseType.getRawClass(); for (NamedType subtype : _registeredSubtypes) { if (rawBase.isAssignableFrom(subtype.getType())) { // yes AnnotatedClass curr = AnnotatedClassResolver.resolveWithoutSuperTypes(config, subtype.getType()); _collectAndResolve(curr, subtype, config, ai, collected); Collection<NamedType> st = ai.findSubtypes(property); if (st != null) { for (NamedType nt : st) { AnnotatedClass ac = AnnotatedClassResolver.resolveWithoutSuperTypes(config, nt.getType()); _collectAndResolve(ac, nt, config, ai, collected); NamedType rootType = new NamedType(rawBase, null); AnnotatedClass ac = AnnotatedClassResolver.resolveWithoutSuperTypes(config, rawBase);
@Override public List<? extends Module> getJacksonModules() { return Collections.singletonList( new SimpleModule("AvroInputRowParserModule") .registerSubtypes( new NamedType(AvroStreamInputRowParser.class, "avro_stream"), new NamedType(AvroHadoopInputRowParser.class, "avro_hadoop"), new NamedType(AvroParseSpec.class, "avro") ) .setMixInAnnotation(Repository.class, RepositoryMixIn.class) .setMixInAnnotation(JsonUtil.class, JsonUtilMixIn.class) .setMixInAnnotation(InMemoryRepository.class, InMemoryRepositoryMixIn.class) ); }
@Override public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config, AnnotatedClass type) { final AnnotationIntrospector ai = config.getAnnotationIntrospector(); HashMap<NamedType, NamedType> subtypes = new HashMap<NamedType, NamedType>(); // then consider registered subtypes (which have precedence over annotations) if (_registeredSubtypes != null) { Class<?> rawBase = type.getRawType(); for (NamedType subtype : _registeredSubtypes) { // is it a subtype of root type? if (rawBase.isAssignableFrom(subtype.getType())) { // yes AnnotatedClass curr = AnnotatedClassResolver.resolveWithoutSuperTypes(config, subtype.getType()); _collectAndResolve(curr, subtype, config, ai, subtypes); } } } // and then check subtypes via annotations from base type (recursively) NamedType rootType = new NamedType(type.getRawType(), null); _collectAndResolve(type, rootType, config, ai, subtypes); return new ArrayList<NamedType>(subtypes.values()); }
HashMap<NamedType, NamedType> collectedSubtypes) if (!namedType.hasName()) { String name = ai.findTypeName(annotatedType); if (name != null) { namedType = new NamedType(namedType.getType(), name); if (namedType.hasName()) { NamedType prev = collectedSubtypes.get(namedType); if (!prev.hasName()) { collectedSubtypes.put(namedType, namedType); Collection<NamedType> st = ai.findSubtypes(annotatedType); if (st != null && !st.isEmpty()) { for (NamedType subtype : st) { AnnotatedClass subtypeClass = AnnotatedClassResolver.resolveWithoutSuperTypes(config, subtype.getType()); _collectAndResolve(subtypeClass, subtype, config, ai, collectedSubtypes);
public StringComparatorModule() { super("StringComparatorModule"); setMixInAnnotation(StringComparator.class, StringComparatorMixin.class); registerSubtypes( new NamedType(StringComparators.LexicographicComparator.class, StringComparators.LEXICOGRAPHIC_NAME), new NamedType(StringComparators.AlphanumericComparator.class, StringComparators.ALPHANUMERIC_NAME), new NamedType(StringComparators.StrlenComparator.class, StringComparators.STRLEN_NAME), new NamedType(StringComparators.NumericComparator.class, StringComparators.NUMERIC_NAME), new NamedType(StringComparators.VersionComparator.class, StringComparators.VERSION_NAME) ); }
@Override public Collection<NamedType> collectAndResolveSubtypesByTypeId(MapperConfig<?> config, AnnotatedClass baseType) { final Class<?> rawBase = baseType.getRawType(); Set<Class<?>> typesHandled = new HashSet<Class<?>>(); Map<String,NamedType> byName = new LinkedHashMap<String,NamedType>(); NamedType rootType = new NamedType(rawBase, null); _collectAndResolveByTypeId(baseType, rootType, config, typesHandled, byName); if (_registeredSubtypes != null) { for (NamedType subtype : _registeredSubtypes) { // is it a subtype of root type? if (rawBase.isAssignableFrom(subtype.getType())) { // yes AnnotatedClass curr = AnnotatedClassResolver.resolveWithoutSuperTypes(config, subtype.getType()); _collectAndResolveByTypeId(curr, subtype, config, typesHandled, byName); } } } return _combineNamedAndUnnamed(rawBase, typesHandled, byName); }
/** * Method for adding set of subtypes to be registered with * {@link ObjectMapper} * this is an alternative to using annotations in super type to indicate subtypes. */ public SimpleModule registerSubtypes(Class<?> ... subtypes) { if (_subtypes == null) { _subtypes = new LinkedHashSet<>(); } for (Class<?> subtype : subtypes) { _checkNotNull(subtype, "subtype to register"); _subtypes.add(new NamedType(subtype)); } return this; }
private boolean resolveSubtypes(Schema model, BeanDescription bean, ModelConverterContext context) { final List<NamedType> types = _intr.findSubtypes(bean.getClassInfo()); if (types == null) { return false; final Class<?> beanClass = bean.getClassInfo().getAnnotated(); for (NamedType subtype : types) { final Class<?> subtypeType = subtype.getType(); if (!beanClass.isAssignableFrom(subtypeType)) { continue; Class<?> currentType = subtype.getType(); if (StringUtils.isNotBlank(composedSchema.getName())) { context.defineModel(composedSchema.getName(), composedSchema, new AnnotatedType().type(currentType), null);
private boolean isSubtype(AnnotatedClass childClass, Class<?> parentClass) { final BeanDescription parentDesc = _mapper.getSerializationConfig().introspectClassAnnotations(parentClass); List<NamedType> subTypes =_intr.findSubtypes(parentDesc.getClassInfo()); if (subTypes == null) { return false; } for (NamedType subtype : subTypes) { final Class<?> subtypeType = subtype.getType(); if (childClass.getRawType().isAssignableFrom(subtypeType)) { return true; } } return false; }
public static List<Class> getSubtypeClasses(ObjectMapper mapper, Class c) { return getSubtypeClasses(mapper.getDeserializationConfig(), c); } public static List<Class> getSubtypeClasses(MapperConfig config, Class c) { AnnotationIntrospector ai = config.getAnnotationIntrospector(); AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(c, ai, config); List<NamedType> subtypes = ai.findSubtypes(ac); List<Class> result = new ArrayList<>(); if (subtypes != null) { for (NamedType subtype : subtypes) { result.add(subtype.getType()); } } return result; }
protected String _subTypeName(NamedType type) { return type.getType().getName(); }
@Override public List<? extends Module> getJacksonModules() { return Collections.<Module>singletonList( new SimpleModule("DoublesQuantilesSketchModule") .registerSubtypes( new NamedType(DoublesSketchAggregatorFactory.class, DOUBLES_SKETCH), new NamedType(DoublesSketchMergeAggregatorFactory.class, DOUBLES_SKETCH_MERGE), new NamedType(DoublesSketchToHistogramPostAggregator.class, DOUBLES_SKETCH_HISTOGRAM_POST_AGG), new NamedType(DoublesSketchToQuantilePostAggregator.class, DOUBLES_SKETCH_QUANTILE_POST_AGG), new NamedType(DoublesSketchToQuantilesPostAggregator.class, DOUBLES_SKETCH_QUANTILES_POST_AGG), new NamedType(DoublesSketchToStringPostAggregator.class, DOUBLES_SKETCH_TO_STRING_POST_AGG) ).addSerializer(DoublesSketch.class, new DoublesSketchJsonSerializer()) ); }
AnnotatedMember property, JavaType baseType) final AnnotationIntrospector ai = config.getAnnotationIntrospector(); Class<?> rawBase = baseType.getRawClass(); NamedType rootType = new NamedType(rawBase, null); AnnotatedClass ac = AnnotatedClassResolver.resolveWithoutSuperTypes(config, rawBase); Collection<NamedType> st = ai.findSubtypes(property); if (st != null) { for (NamedType nt : st) { ac = AnnotatedClassResolver.resolveWithoutSuperTypes(config, nt.getType()); _collectAndResolveByTypeId(ac, nt, config, typesHandled, byName); for (NamedType subtype : _registeredSubtypes) { if (rawBase.isAssignableFrom(subtype.getType())) { // yes AnnotatedClass curr = AnnotatedClassResolver.resolveWithoutSuperTypes(config, subtype.getType()); _collectAndResolveByTypeId(curr, subtype, config, typesHandled, byName);