Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rainzhou2012 opened this issue Aug 17, 2023 · 0 comments
Closed

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

rainzhou2012 opened this issue Aug 17, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@rainzhou2012
Copy link

rainzhou2012 commented Aug 17, 2023

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();
      ......
    }
@bnasslahsen bnasslahsen added the bug Something isn't working label Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants