Group dynamic attributes by category in REST

Hi team,

Jmix version: 2.1

Suppose I have 2 categories of dynamic attributes named cate1 and cat2, is it possible to extend some bean to make it showing cat1:{prop1:'xxx'},cat2:{prop2:'xxx'} in the output of REST when loading entities?


Solution using DynAttr API

We can find all categories just from database, iterate over it’s attributes and using DynAttr API fetch it all:

public class UserController {
    public DataManager dataManager;
    public ExtendedEntities extendedEntities;
    public Metadata metadata;

    public List<Map<User, Map<String, Map<String, Object>>>> listUsers() {

        List<Category> categoriesForUser = dataManager.load(Category.class)
                .query("select e from dynat_Category e where e.entityType = :entityType")
                .parameter("entityType", metadata.getClass(User.class).getName())

        return dataManager.load(User.class)
                .hint(DynAttrQueryHints.LOAD_DYN_ATTR, true)
                .map(user -> {
                    Map<User, Map<String, Map<String, Object>>> dynAttrMapping = new HashMap<>();
                    var userAttrs =
                                    c -> c.getCategoryAttrs()
                                                    a -> {
                                                        var value = EntityValues.getValue(user, "+" + a.getCode());
                                                        return Objects.requireNonNullElse(value, "null");

                    dynAttrMapping.put(user, userAttrs);
                    return dynAttrMapping;



Regards, Dmitry

1 Like