RYJ
RYJ

Reputation: 439

How to use List with JDL entities in Jhipster

I'm new to use Jhipster. I want to create a JDL entity using my existing model classes. Here is my model class.

@Data
public class ResponseJson implements Serializable {
    private List<String> names;
}

Normal JDL entity can be created like,

entity ResponseJson{
  names String
}

But I need to know how to use List in JDL entities.

Upvotes: 4

Views: 6821

Answers (3)

Ranjul Arumadi
Ranjul Arumadi

Reputation: 111

Jhipsters page on Field types and validations discusses the available JDL types.

Currently, it does not support List, text[] etc directly.

For people who want to create entities having these types, one workaround is to make the entity with the types that Jhipster JDL offers and then use Liquibase to add the other fields types like List, text[] etc.

Upvotes: 0

Alexandre GC
Alexandre GC

Reputation: 563

If you want to opt for a solution that is not using JDL, you can change you model to use a List like this:

public class ResponseJson implements Serializable {
    @ElementCollection
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<String> names = new HashSet<>();

    ...

}

Upvotes: 0

chrisdns
chrisdns

Reputation: 514

You cannot use List directly

Instead you can create a one-to-many relationship in order to make ResponseJson have multiple String by wrapping this String in another Object

Your JDL should be:

entity ResponseJson {
    ...
}

entity ObjectContainingString {
    name String
}

relationship OneToMany {
    ResponseJson{name} to ObjectContainingString{json}
} 

Upvotes: 6

Related Questions