I am trying to convert Java Object to JSON using Groovy JsonBuilder
Java POJO Class
public class Employee {
String name;
int age;
@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
Groovy Script
Employee employee = new Employee();
employee.name="Vinod"
employee.age=24
println new JsonBuilder( employee ).toPrettyString()
Output
{
}
I am not sure if I am using JsonBuilder incorrectly. Please help