Hello I had this follow json code.
[{"check":{"domain":"qwe.coedu.br"}},{"check":{"domain":"qwe.com.br"}},{"check":{"domain":"qwe.com"}}]"
How do to convert this json in my object
class Check {String domain , String status ...}
It return a List<Check>, but the Check attributes are null. See my code. with Gson.
Gson gson = new Gson();
Type fooType = new TypeToken<Collection<Check>>(){}.getType();
System.out.println(((List<Check>)gson.fromJson("[{\"check\":{\"status\":\"2\",\"domain\":\"william.com.br\"}}]", fooType)).get(0).getDomain());
When I debug my returned list, this contains all objects in list, but all with your attributes null.
What is wrong ?
You need a customized converter, because you have a list of objects that holds a property named
check. And this property is of a class that has the propertiesdomainandstatus.Two possibilities here:
JsonDeserializer, in which you will instanciate yourCheckobject and then set the properties by your own is the best choice;checkproperty of a type that holds a property nameddomainand another onestatus.For the second case is pretty clear what needs to be done, but for the first case you could do something like: