• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Creating a java bean with selected fields data populated at runtime

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic