Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用spring返回HTTP请求时可能存在多种类型的JSON文件_Android_Json_Spring_Jackson - Fatal编程技术网

Android 使用spring返回HTTP请求时可能存在多种类型的JSON文件

Android 使用spring返回HTTP请求时可能存在多种类型的JSON文件,android,json,spring,jackson,Android,Json,Spring,Jackson,我使用Spring for Android作为HTTP客户端。假设我使用基本身份验证执行请求,如下所示: // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

我使用Spring for Android作为HTTP客户端。假设我使用基本身份验证执行请求,如下所示:

    // Create a new RestTemplate instance
            RestTemplate restTemplate = new RestTemplate();
            restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());


            try {
                // Make the network request
                Log.d(TAG, url);
                ResponseEntity<Message> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<Object>(requestHeaders), Message.class);
                System.out.println(response.toString());
            } catch (HttpClientErrorException e) {
                Log.e(TAG, e.getLocalizedMessage(), e);
e.getLocalizedMessage());
            }
        }
但是当用户没有自动调整大小时,数据就会丢失(偏离轨道)。看起来是这样的

 {

    "message": "You are not authorized to use this service",
    "code": 5201

}
但这是两种类型的JSON文件,如何为这两种文件创建正确的映射(消息类)?或者我应该创建不同类型的消息类


恐怕这个问题有一个相当直截了当的答案,但我自己找不到。我希望有人能给我解释一下,谢谢

两个json相同,唯一的区别是第二个json数据将为空

 {

    "message": "You are not authorized to use this service",
    "code": 5201

}