I am trying to deserialize the following JSON:
[{
"customerDetails":
{
"customer_name": "name",
"customer_email": "email"
},
"shippingDetails":
{
"shipping_contact": "name",
"shipping_street": "Av:"
}
}]
Array
(
[0] => Array
(
[customerDetails] => Array
(
[customer_name] => name
[customer_email] => email
)
[shippingDetails] => Array
(
[shipping_contact] => shipname
[shipping_street] => Av:Name
)
)
)
Heres my classes:
public class Order {
private List<CustomerDetail> customerDetail;
private List<Shipping> shipping;
//getters and setters
}
public class Shipping {
private String contact;
private String street;
//getters and setters
}
public class CustomerDetail{
private String name;
private String email;
//getters and setters
}
I tried this:
Gson g = new Gson();
Order[] order = g.fromJson(new FileReader("jason"), Order[].class);
List <CustomerDetail> cd = order[0].getCustomerDetail();
System.out.println(cd.get(0).getName());
But I keep gettin either NullPointer or
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2