• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HELP How can i get the data type and fieldName from a POJO properties

 
regoj nastocare
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI im from México

well i hope i can explain this well

Is there a way to get the type of a property of a pojo

public class Cat {
private Long id; // identifier
private Date birthdate;
private float weight;
private void setId(Long id) {
this.id=id;
}

for example i want to know the datatype of birthday, im writing a function for this but is there another simple way?


Another Question
And too i have a function called getFieldbyName this haver MANY "if" some like this

public String getFieldByName(String sFieldName) {
String sRetorno = "";
if( sFieldName.equals("CVE_ENTIDAD" ) ){
sRetorno = getId().getCveEntidad();
} else if( sFieldName.equals("TIPOPAGO") ){
sRetorno = String.valueOf(getId().getTipopago());
}...

how can i simpliy this???




Another ONE

I need get the property when i know the FIELDNAME i made this

public static String getPropertyByField(String campo){
String propiedadRetorno = "";
if(campo.equalsIgnoreCase("CVE_ENTIDAD")){
propiedadRetorno = "id.cveEntidad";
}else if(campo.equalsIgnoreCase("ID_EMPRESA")){
propiedadRetorno = "id.idEmpresa";
}...

How you can see not is very useful, but its working, i like rewrite this better, can someone tell me any tip?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What ORM are you using?

In EclipseLink,

session.getDescriptor(object).getObjectBuilder().extractValueFromObjectForField(object, new DatabaseField(column), session)
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the first one,


For the second one, if you're not using any ORM, try using a simple Map.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic