I want to convert a Spark dataframe to a dataset of a POJO with different fields names. I have a dataframe of the fields: name, date_of_birth, where their types are StringType, DateType.
And a POJO of:
public class Person implements Serializable {
private String name;
private Date dateOfBirth;
}
I convert it to dataset successfully with the following code:
Encoder<Person> personEncoder = Encoders.bean(Person.class);
Dataset<Person> personDS = result.as(personEncoder);
List<Person> personList = personDS.collectAsList();
Only if I change the dataframe’s columns names before that, to those of the Person POJO. Is there any way of telling Spark to map between the fields from the POJO side?
I thought about Gson’s @SerializedName(“date_of_birth”) but it didn’t affect anything.