Reputation: 23805
I have a POJO
class like as below :-
public class Pojo {
String param1
List param2
Map param3
Boolean param4
Integer param5
}
I have a List
which contains Map
objects with the same structure as like Pojo
:-
List list = [
[param1: "a", param2: ["a","b","c"], param3:[a:"a",b:"b",c:"c"], param4:true, param5:1],
[param1: "b", param2: ["d","e","f"], param3:[d:"d",e:"e",f:"f"], param4:false, param5:2]
]
Now I want to convert this list of maps to list of pojo objects
Anyone have idea how to convert it??
Upvotes: 1
Views: 1743
Reputation: 187529
It's a one-liner....
// here's the class we want to convert to
public class Pojo {
String param1
List param2
Map param3
Boolean param4
Integer param5
}
// here the data we want to convert
List list = [
[param1: "a", param2: ["a","b","c"], param3:[a:"a",b:"b",c:"c"], param4:true, param5:1],
[param1: "b", param2: ["d","e","f"], param3:[d:"d",e:"e",f:"f"], param4:false, param5:2]
]
// this is the conversion
List<Pojo> pojos = list.collect { new Pojo(it) }
Upvotes: 1