class AndroidJsonHandler implements KeenJsonHandler {

    @Override
    public Map<String, Object> readJson(Reader reader) throws IOException {
        if (reader == null) {
            throw new IllegalArgumentException("Reader must not be null");
        }

        String json = readerToString(reader);
        try {
            Object jsonObjOrArray = getJsonObjectManager().newTokener(json).nextValue();

            // Issue #99 : Take a look at better dealing with root Map<> vs root List<> in the
            // response.

            Object rootNode = JsonHelper.fromJson(jsonObjOrArray);
            Map<String, Object> rootMap = null;

            if (null == rootNode) {
                throw new IllegalArgumentException("Empty reader or ill-formatted JSON " +
                                                   "encountered.");
            } else if (rootNode instanceof Map) {
                rootMap = (Map)rootNode;
            } else if (rootNode instanceof List) {
                rootMap = new LinkedHashMap<String, Object>();
                rootMap.put(KeenConstants.KEEN_FAKE_JSON_ROOT, rootNode);
            }

            return rootMap;
        } catch (JSONException e) {
            throw new IOException(e);
        }
    }

}