class java.lang.Long cannot be cast to class java.lang.String error when having a hashmap of mixed types (Long and string)

I have spring boot – camel application that connects to a postgre database and returms from a select query the following array:

[{id=1, name=JENNY, country=LB}, {id=2, name=AMIGOSCODE, country=UK}]

id is of type bigint in the database however name is of type string

when executing the following code:

public class InsertRestService extends RouteBuilder {


    public void configure() throws Exception {


        .transform().simple("SELECT * FROM person WHERE name=" + "'${}'")
        .to("jdbc:dataSource") //spring boot starter jdbc creates the bean in the registry
        .process(new Processor() {
            public void process(Exchange xchg) throws Exception {
               //the camel jdbc select query has been executed. We get the list of employees.
                ArrayList<HashMap<String, String>> dataList = (ArrayList<HashMap<String, String>>) xchg.getIn().getBody();
                List<EmployeeInfo> employees = new ArrayList<EmployeeInfo>();
                for (HashMap<String, String> data : dataList) {
                    EmployeeInfo employee = new EmployeeInfo();

I am getting the following error:

java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.lang.String (java.lang.Long and java.lang.String are in module java.base of loader 'bootstrap')

I think it is because of the hashmap HashMap<String, String> having the types string but I don t know how to do it since I have mixed types in hashMap.

Also I have a class:

public class EmployeeInfo {

    private String empId;
    private String empName;

    public String getEmpId() {
        return empId;

    public void setEmpId(String empId) {
        this.empId = empId;

    public String getEmpName() {
        return empName;

    public void setEmpName(String empName) {
        this.empName = empName;

    public String toString() {
        return "[empId=" + empId + ", empName=" + empName + "]";


when trying to change the type of empId to “long“` it does not work as well.

I would appreciate any help! Thanks in advance!


Did you try converting

ArrayList<HashMap<String, String>>


ArrayList<HashMap<String, Object>>

Post that based on your field name when you do data.get() you can type cast it to required type by instance checking.

Also, if you want to check types: you can add a log before each field access

Object obj = data.get(<field>);

Hope this is helpful.