In spring I am using jdbcTemplate, but having a problem that it is returning a Linkedcaseinsensitivemap when querying for a List, when doing the following I still get the sp
A SQL select can return multiple rows, and each row has multiple selected columns. The queryForList method you are calling returns a List with for each selected row a Map mapping column name to column value.
Map and List are interfaces, so Spring is free to pick whatever implementation it likes. It chooses the LinkedCaseInsensitiveHashMap for the Map because that map will list the keys in the order of insertion. So the order in which the columns were selected does not get lost.
If you wish to send the result list to a receiver that you know little about, you can probably best serialize it to JSON and send it as a text message.
You can serialize to JSON using a library like Gson or Jackson2. You create a serializer and feed it the object you wish to convert to a String. So for example in Gson, where the serializer class is called Gson:
TextMessage message;
// initialize message and headers however you like
// then serialize it to String:
Gson gson = new Gson();
String json = gson.toJson(list);
// and set it in the message:
message.setText(json);
(You can also let Spring JmsTemplate do this for you using a MessageConverter that converts to JSON but I'd estimate that that's a bit harder to get working.)
Alternatively, if you wish to customize the Map that you send as an ObjectMessage, you can use a different query method that allows you to specify a custom RowMapper that creates a java.util.Map implementation of your liking. Note that if you use a TreeMap, it'll sort the columns alphabetically and if you use a HashMap, it'll put them in random order.
The receiver then can unpack the JSON back into Java objects. gson.fromGson(json) will return a List of Maps.
This is the only way I've figured out how to have a child object to become it's parent class without breaking out into methods - in my described scenario doing the following:
final java.util.ArrayList<java.util.Map<String, Object>> javaList = new java.util.ArrayList<java.util.Map<String, Object>>();
final java.util.List<java.util.Map<String, Object>> list = jdbc
.queryForList("SELECT * FROM customer");
javaList.addAll(list);
But doesn't look good to me, how would one achive this in a more right way?