Home > front end >  How to create a Model class having map as one of the variables
How to create a Model class having map as one of the variables

Time:08-12

I am trying to create a model class for something like this

    "id": null,
    "name": "TestCompany",
    "domainName": "comany.domain",
    "status": 0,
    "brandAttributes": {
        "contact_person_name": "HS",
        "website_url": "[email protected]",
        "address": "Bengaluru",
        "contact_person_email": "[email protected]"
    }
}

CodePudding user response:

You should create a class Brand and define attributes of brand object. Then, you can define an attribute private Brand brand for company object like this

public class Company {
    
    private String id;
    
    private String name;    

    private Brand brand;
}

CodePudding user response:

You can use nested class or 2 class to archive the Model

class ModelDTO{
    private String id;
    private String name;
    private String domainName;
    private long status;
    private BrandAttributes brandAttributes;
    
    class BrandAttributes{
        private String contact_person_name;
        private String website_url;
        private String address;
        private String contact_person_email;
    }
}

or

class ModelDTO{
    private String id;
    private String name;
    private String domainName;
    private long status;
    private BrandAttributes brandAttributes;
}
    class BrandAttributes{
        private String contact_person_name;
        private String website_url;
        private String address;
        private String contact_person_email;
    }
  • Related