use of org.codehaus.jackson.annotate.JsonTypeInfo in project typescript-generator by vojtechhabarta.
the class Jackson1Parser method parseBean.
private BeanModel parseBean(SourceType<Class<?>> sourceClass) {
final List<PropertyModel> properties = new ArrayList<>();
final BeanHelper beanHelper = getBeanHelper(sourceClass.type);
if (beanHelper != null) {
for (final BeanPropertyWriter beanPropertyWriter : beanHelper.getProperties()) {
final Member member = beanPropertyWriter.getMember().getMember();
final PropertyMember propertyMember = wrapMember(settings.getTypeParser(), member, /*creatorIndex*/
null, beanPropertyWriter::getAnnotation, beanPropertyWriter.getName(), sourceClass.type);
if (propertyMember == null) {
continue;
}
Type propertyType = beanPropertyWriter.getGenericPropertyType();
if (!isAnnotatedPropertyIncluded(beanPropertyWriter::getAnnotation, sourceClass.type.getName() + "." + beanPropertyWriter.getName())) {
continue;
}
final boolean optional = isPropertyOptional(propertyMember);
properties.add(processTypeAndCreateProperty(beanPropertyWriter.getName(), propertyType, null, optional, null, sourceClass.type, member, null, null));
}
}
final JsonTypeInfo jsonTypeInfo = sourceClass.type.getAnnotation(JsonTypeInfo.class);
if (jsonTypeInfo != null && jsonTypeInfo.include() == JsonTypeInfo.As.PROPERTY) {
if (!containsProperty(properties, jsonTypeInfo.property())) {
properties.add(new PropertyModel(jsonTypeInfo.property(), String.class, false, null, null, null, null, null));
}
}
final JsonSubTypes jsonSubTypes = sourceClass.type.getAnnotation(JsonSubTypes.class);
if (jsonSubTypes != null) {
for (JsonSubTypes.Type type : jsonSubTypes.value()) {
addBeanToQueue(new SourceType<>(type.value(), sourceClass.type, "<subClass>"));
}
}
final Type superclass = sourceClass.type.getGenericSuperclass() == Object.class ? null : sourceClass.type.getGenericSuperclass();
if (superclass != null) {
addBeanToQueue(new SourceType<>(superclass, sourceClass.type, "<superClass>"));
}
final List<Type> interfaces = Arrays.asList(sourceClass.type.getGenericInterfaces());
for (Type aInterface : interfaces) {
addBeanToQueue(new SourceType<>(aInterface, sourceClass.type, "<interface>"));
}
return new BeanModel(sourceClass.type, superclass, null, null, null, interfaces, properties, null);
}
Aggregations