springfox: Cycles in Java classes cause infinite loop in ModelAttributeParameterExpander
When using JPA, Hibernate, and other ORMs, it’s common for each side of a relationship to refer to the other. For example:
class Person {
private String firstName;
private String lastName;
private Address address;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address= address;
}
}
class Address {
private String street;
@ApiModelProperty(hidden = true)
private Person person;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public Person getPerson() {
return person;
}
public void setPerson(person person) {
this.person= person;
}
}
Currently, this set of classes causes an infinite loop resulting in a StackOverflowError in com.mangofactory.swagger.readers.operation.parameter.ModelAttributeParameterExpander.expand(String, Class<?>, List<Parameter>). The problem is that the Java classes are expanded but the annotation which would cause the field to be excluded is being processed, so Person references Address references Person… and the expansion continues infinitely.
I think the solution is to simply process @ApiModelProperty(hidden = true) annotations at expansion time. It may also be nice to detect when such cycles occur and throw a descriptive error (instead of getting a StackOverflowError) but that’s just a nice to have… solving the problem would quite sufficient 😃
Thanks!
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 16 (10 by maintainers)
help me .