List of usage examples for com.fasterxml.jackson.databind JavaType isEnumType
public final boolean isEnumType()
From source file:org.candlepin.swagger.CandlepinSwaggerModelConverter.java
public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> next) { JavaType propType = null; /**//from w w w . j av a 2s . co m * See java doc of NestedComplexType. This unwrapping makes sure that a * real type of field is passed to _mapper */ if (type instanceof NestedComplexType) { propType = pMapper.constructType(((NestedComplexType) type).getOriginalType()); } else { propType = pMapper.constructType(type); } log.debug("resolveProperty {}", propType); Property property = null; if (propType.isContainerType()) { JavaType keyType = propType.getKeyType(); JavaType valueType = propType.getContentType(); if (keyType != null && valueType != null) { property = new MapProperty() .additionalProperties(context.resolveProperty(valueType, new Annotation[] {})); } else if (valueType != null) { ArrayProperty arrayProperty = new ArrayProperty() .items(context.resolveProperty(valueType, new Annotation[] {})); if (pIsSetType(propType.getRawClass())) { arrayProperty.setUniqueItems(true); } property = arrayProperty; } } else { property = PrimitiveType.createProperty(propType); } if (property == null) { if (propType.isEnumType()) { property = new StringProperty(); pAddEnumProps(propType.getRawClass(), property); } else if (pIsOptionalType(propType)) { property = context.resolveProperty(propType.containedType(0), null); } else { // complex type Model innerModel = context.resolve(type); if (innerModel instanceof ModelImpl) { ModelImpl mi = (ModelImpl) innerModel; property = new RefProperty( StringUtils.isNotEmpty(mi.getReference()) ? mi.getReference() : mi.getName()); } } } return property; }
From source file:org.candlepin.swagger.CandlepinSwaggerModelConverter.java
public Model resolve(Type rawType, ModelConverterContext context, Iterator<ModelConverter> next) { if (this.shouldIgnoreClass(rawType)) { return null; }/* w ww . j a va 2 s.c om*/ /** * See java doc of NestedComplexType. This unwrapping makes sure that a * real type of field used throughout the method. At the same time flag * 'isNested' helps to indicate later in the method that this type may * be introspected as Hateoas enabled field */ boolean isNested = false; if (rawType instanceof NestedComplexType) { isNested = true; NestedComplexType nested = (NestedComplexType) rawType; rawType = nested.getOriginalType(); } JavaType type = pMapper.constructType(rawType); if (type.isEnumType() || PrimitiveType.fromType(type) != null) { // We don't build models for primitive types return null; } final BeanDescription beanDesc = pMapper.getSerializationConfig().introspect(type); // Couple of possibilities for defining String name = isNested ? "Nested" : ""; name += pTypeName(type, beanDesc); if ("Object".equals(name)) { return new ModelImpl(); } final ModelImpl model = new ModelImpl().type(ModelImpl.OBJECT).name(name) .description(pDescription(beanDesc.getClassInfo())); if (!type.isContainerType()) { // define the model here to support self/cyclic referencing of // models context.defineModel(name, model, type, null); } if (type.isContainerType()) { // We treat collections as primitive types, just need to add models // for values (if any) context.resolve(type.getContentType()); return null; } // if XmlRootElement annotation, construct an Xml object and attach it // to the model XmlRootElement rootAnnotation = beanDesc.getClassAnnotations().get(XmlRootElement.class); if (rootAnnotation != null && !"".equals(rootAnnotation.name()) && !"##default".equals(rootAnnotation.name())) { log.debug(rootAnnotation.toString()); Xml xml = new Xml().name(rootAnnotation.name()); if (rootAnnotation.namespace() != null && !"".equals(rootAnnotation.namespace()) && !"##default".equals(rootAnnotation.namespace())) { xml.namespace(rootAnnotation.namespace()); } model.xml(xml); } // see if @JsonIgnoreProperties exist Set<String> propertiesToIgnore = new HashSet<String>(); JsonIgnoreProperties ignoreProperties = beanDesc.getClassAnnotations().get(JsonIgnoreProperties.class); if (ignoreProperties != null) { propertiesToIgnore.addAll(Arrays.asList(ignoreProperties.value())); } final ApiModel apiModel = beanDesc.getClassAnnotations().get(ApiModel.class); String disc = (apiModel == null) ? "" : apiModel.discriminator(); if (apiModel != null && StringUtils.isNotEmpty(apiModel.reference())) { model.setReference(apiModel.reference()); } if (disc.isEmpty()) { // longer method would involve // AnnotationIntrospector.findTypeResolver(...) but: JsonTypeInfo typeInfo = beanDesc.getClassAnnotations().get(JsonTypeInfo.class); if (typeInfo != null) { disc = typeInfo.property(); } } if (!disc.isEmpty()) { model.setDiscriminator(disc); } List<Property> props = new ArrayList<Property>(); for (BeanPropertyDefinition propDef : beanDesc.findProperties()) { parseProperty(context, isNested, beanDesc, propertiesToIgnore, props, propDef); } Collections.sort(props, getPropertyComparator()); Map<String, Property> modelProps = new LinkedHashMap<String, Property>(); for (Property prop : props) { modelProps.put(prop.getName(), prop); } model.setProperties(modelProps); /** * This must be done after model.setProperties so that the model's set * of properties is available to filter from any subtypes **/ if (!resolveSubtypes(model, beanDesc, context)) { model.setDiscriminator(null); } return model; }