Hi Alfonso, > -----Original Message----- > From: Alfonso Via-Reque > [mailto:avia...@yahoo.com.INVALID] > Sent: Thursday, January 19, 2017 5:27 AM > To: user@commons.apache.org > Subject: Read file into POJO > > Hello Commons Users, > I'm looking for a way to read files directly into POJOs. The > idea is that the file layout would be defined in an > "properties"-type file (XML or something). The layout > could be delimited or fixed-width, with the layout file > defining the columns and which POJO member variable > they should be set to. > For example, a file might be tilde (~) delimited and follow > this layout:ID~first name~last > name~age~address~city~state~zip
On how to define the layout you can use: - XML, you can rely on Commons Configuration - ~ delimeted, rely on standard Java class FileInputReader and StringTokenizer > I'd like to read it into a class: > public class Person { private Integer id; > private String firstName; > private String lastName; private Integer age; private > String address; private String city; > private String state; > private String zip; > > // Getters and Setters ... > } > > Is there a tool that do this? take a look at Apache Commons BeanUtils http://commons.apache.org/proper/commons-beanutils/ as stated in the user guide http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.3/apidocs/org/apache/commons/beanutils/package-summary.html#standard you can access your accessor method via PropertyUtils.getSimpleProperty(anIstanceOfPerson,"firstName") > > ThanksAlfonso Hope it helps. S. ________________________________ Le informazioni contenute in questo messaggio di posta elettronica sono da considerarsi riservate e confidenziali. Il loro utilizzo è consentito esclusivamente al destinatario in indirizzo e ne è vietata la diffusione in qualunque modo eseguita, salvo che ne sia data espressa autorizzazione dal mittente. Nel caso in cui il messaggio Le fosse pervenuto per errore, La invitiamo gentilmente ad eliminarlo in modo permanente dopo averne dato tempestiva comunicazione al mittente e a non utilizzare in alcun caso il suo contenuto. Qualsivoglia utilizzo non autorizzato di questo messaggio e dei suoi eventuali allegati espone il responsabile alle relative conseguenze civili e penali. This communication is confidential and the use of the contained information is allowed solely for the intended recipient. Its disclosure, distribution or copying is prohibited, unless expressly authorized by the sender. If you receive this communication by mistake please notify us and delete the message and its attachments. Anyone responsible for the unauthorized use of this message and its attachments is liable to face legal consequences.