PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 20, 2022

[FIXED] How to create a Model class having map as one of the variables

 September 20, 2022     hashmap, java, spring, spring-boot     No comments   

Issue

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": "company@gmail.com",
        "address": "Bengaluru",
        "contact_person_email": "hs@gmail.com"
    }
}

Solution

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;
    }


Answered By - Lokeshwar G
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing