Interesting idea. The way I would do it:

  1. Ingest your data in a dataframe.
  2. Write a utility method that takes the dataframe and class name (here SampleRecord).
  3. Use introspection to read the annotations (you could eventually add some if you need to define specific properties).
  4. Rename the columns with withColumnRenamed() on the dataframe.
  5. Return the modified dataframe.



public class SampleRecord implements Serializable {
         private Long sampleId;

         private String name;

         private String description; 

public void setSampleId(Long sampleId) {
        this.sampleId = sampleId;

public void setName(String name) { = name;

public void setDescription(String description) {
        this.description = description;

Related Query

More Query from same tag