• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a java bean with selected fields data populated at runtime  RSS feed

 
Kesava Krishna
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am having a bean object with 10 fields and corresponding getters and setters. At run time I have to create multiple such bean objects but provided with not all the fields populated with data. Based on my selection some beans objects should have data filled for 5 fields and some other bean objects should have data filled for last 5 fields.
Tried using .getClass().getDeclaredFields(), but it filling data for all the fields.
Appreciate your help here.

Thanks,
Kesava
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by not having all the fields populated? I think we need more details: code example that shows what you are doing and shows how it misbehaves, and a description of how that is different than expected.

This sounds like a design problem to me, though. If you have two cases, with case 1 having the first five fields and case 2 having the second five fields, why are you putting all ten fields in one class? you should probably have two different classes, each with just the fields you expect in each of the two cases. Or perhaps have two interfaces which define the two different groups of data. Then, even if you have one class implement both interfaces you can assign the instances to the interface to limit access to just the data you intend to give access to.

But I really don't understand your problem, so maybe that last paragraph doesn't apply...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!