Skip to content

Not working if a property of entity contains generic parameters. #2347

Closed
@rainzhou2012

Description

@rainzhou2012

Describe the bug
Entity Class as following.

@Document(indexName = "company")
@Data
@Builder
public class Company {
  @Id
  private String id;

  @Field(type = FieldType.Keyword)
  private String name;

  @Field(type = FieldType.Text)
  private String address;

  private GenericField<String> relation;
}

an object has generic parameters, as following

public class GenericField<T> {

  private T parent;
  private String name;

  public T getParent() {
    return parent;
  }

  public void setParent(T parent) {
    this.parent = parent;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof GenericField<?> that)) return false;
    return Objects.equals(parent, that.parent) && Objects.equals(name, that.name);
  }

  @Override
  public int hashCode() {
    return Objects.hash(parent, name);
  }
}

Repository as following

@Repository
public interface CompanyRepository extends ReactiveCrudRepository<Company, String> {
}

Started my application, errors when accessing springdoc ui.
image

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    spring-boot 3.1.2
    spring-boot-starter-data-rest 3.1.2
    spring-boot-starter-data-elasticsearch 3.1.2

  • What modules and versions of springdoc-openapi are you using?
    springdoc-openapi-starter-webmvc-ui 2.2.0

  • Provide with a sample code (HelloController) or Test that reproduces the problem
    the sample codes as above.

Expected behavior
I did some debug, Looks like customize method in SpringDocDataRestUtils should call persistentEntities.iterator(), not persistentEntities.getManagedTypes().

    Iterator<PersistentEntity<?, ? extends PersistentProperty<?>>> entities = persistentEntities.iterator();
    while(entities.hasNext()) {
      PersistentEntity<?, ? extends PersistentProperty<?>> entity = entities.next();
      TypeInformation<?> typeInformation = entity.getTypeInformation();
      Class entityClass = entity.getType();
      ......
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions