There is json

{ "message":{ "affenpinscher":[], "african":[], "bulldog":["boston","french"], ... "retriever":["chesapeake","curly","flatcoated","golden"] ... "wolfhound":["irish"] } } 

https://dog.ceo/api/breeds/list/all

I'm trying to deserialize this into the following structure >> Here is my deserializer:

 public class BreedDeserializer implements JsonDeserializer<Map<String, List<String>>> { @Override public Map<String, List<String>> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final JsonObject jsonObject = json.getAsJsonObject(); Type type = new TypeToken<Map<String, List<String>>>(){}.getType(); Map<String, List<String>> dogBreeds = context.deserialize(jsonObject.get("message"), type); return dogBreeds; } } 

Before calling the deserialize json-string method, I checked that there was an object "message" with an array of values. But in the end, the method returns null.

    1 answer 1

    According to json specifications, this is absolutely valid.
    Try this:

     public class MessagesResponse { private String status; private Map<List<String>> message; public String getStatus() { return status; } public Message getMessage() { return message; } } 

     MessagesResponse response = gson.fromJson(json, MessagesResponse.class); Map<List<String>> message = response.getMessages();