continue;
}
if (name != null && !elements.containsKey(name)) {
Type fieldType = getModelType(field.type(), nested);
String description = getFieldDescription(field, true);
String min = getFieldMin(field);
String max = getFieldMax(field);
Boolean required = getFieldRequired(field);
String defaultValue = getFieldDefaultValue(field);
String paramCategory = this.composite ? ParserHelper.paramTypeOf(false, this.consumesMultipart, field, fieldType, this.options)
: null;
elements.put(field.name(), new TypeRef(field.name(), paramCategory, " field: " + field.name(), fieldType, description, min, max,
defaultValue, required));
}
}
}
}
// add methods
if (!"javax.xml.bind.annotation.XmlAccessType.FIELD".equals(xmlAccessorType)) {
MethodDoc[] methodDocs = classDoc.methods();
if (methodDocs != null) {
for (MethodDoc method : methodDocs) {
// ignore static methods and private methods
if (method.isStatic() || method.isPrivate() || method.name().charAt(0) == '_') {
continue;
}
// we tie getters and their corresponding methods together via this rawFieldName
String rawFieldName = nameTranslator.methodName(method).value();
String translatedNameViaMethod = this.translator.methodName(method).value();
if (translatedNameViaMethod != null) {
boolean isFieldMethod = rawFieldName != null && (elements.containsKey(rawFieldName) || excludeFields.contains(rawFieldName));
boolean isFieldGetter = isFieldMethod && method.name().startsWith("get");
boolean isFieldSetter = isFieldMethod && method.name().startsWith("set");
boolean excludeMethod = false;
// ignore deprecated methods
excludeMethod = this.options.isExcludeDeprecatedFields() && ParserHelper.isDeprecated(method);
// ignore methods we are to explicitly exclude
if (ParserHelper.hasTag(method, this.options.getExcludeFieldTags())) {
excludeMethod = true;
}
// ignore methods that are for a different json view
ClassDoc[] jsonViews = ParserHelper.getJsonViews(method);
if (!ParserHelper.isItemPartOfView(this.viewClasses, jsonViews)) {
excludeMethod = true;
}
if (isFieldGetter || isFieldSetter) {
// skip if the field has already been excluded
if (excludeFields.contains(rawFieldName)) {
continue;
}
// skip if this method is to be excluded but also remove the field from the elements
// so it doesnt appear in the model
if (excludeMethod) {
elements.remove(rawFieldName);
excludeFields.add(rawFieldName);
continue;
}
// see if the field name should be overwritten via annotations on the getter/setter
// note if the field has its own customizing annotation then that takes precedence
String nameViaField = rawToTranslatedFields.get(rawFieldName);
if (!customizedFieldNames.contains(rawFieldName) && !translatedNameViaMethod.equals(nameViaField)) {
rawToTranslatedFields.put(rawFieldName, translatedNameViaMethod);
customizedFieldNames.add(rawFieldName);
}
TypeRef typeRef = elements.get(rawFieldName);
// the field was already found e.g. class had a field and this is the getter
// check if there are tags on the getter we can use to fill in description, min and max
if (typeRef.description == null) {
typeRef.description = getFieldDescription(method, isFieldGetter);
}
if (typeRef.min == null) {
typeRef.min = getFieldMin(method);
}
if (typeRef.max == null) {
typeRef.max = getFieldMax(method);
}
if (typeRef.defaultValue == null) {
typeRef.defaultValue = getFieldDefaultValue(method);
}
if (typeRef.required == null) {
typeRef.required = getFieldRequired(method);
}
if (this.composite && typeRef.paramCategory == null) {
typeRef.paramCategory = ParserHelper.paramTypeOf(false, this.consumesMultipart, method, typeRef.type, this.options);
}
typeRef.sourceDesc = " method: " + method.name();
} else {
// skip if this method is to be excluded
if (excludeMethod) {
continue;
}
// this is a getter or other method where there wasn't a specific field
String description = getFieldDescription(method, true);
String min = getFieldMin(method);
String max = getFieldMax(method);
String defaultValue = getFieldDefaultValue(method);
Boolean required = getFieldRequired(method);
Type returnType = getModelType(method.returnType(), nested);
String paramCategory = ParserHelper.paramTypeOf(false, this.consumesMultipart, method, returnType, this.options);
elements.put(translatedNameViaMethod, new TypeRef(rawFieldName, paramCategory, " method: " + method.name(), returnType,
description, min, max, defaultValue, required));