Announcement Announcement Module
Collapse
No announcement yet.
[PROBLEM SPRING ANDROID] deserialize object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [PROBLEM SPRING ANDROID] deserialize object

    my code

    PHP Code:
    String url = "http://github.com/api/v2/json/repos/show/schacon/";
        
    HttpHeaders requestHeaders = new HttpHeaders();
            
    List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
            
                                            acceptableMediaTypes.add(MediaType.APPLICATION_JSON);
            
                                            requestHeaders.setAccept(acceptableMediaTypes);
            
                                            
            
    HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
            
    RestTemplate restTemplate = new RestTemplate();
            
    ResponseEntity<Repositorie[]> responseEntity = restTemplate.exchange(url, 
                                                    HttpMethod.GET, requestEntity, Repositorie[].class);
    the error

    PHP Code:
    02-23 00:59:22.815ERROR/AndroidRuntime(433): Caused byorg.codehaus.jackson.map.JsonMappingExceptionCan not deserialize instance of com.androidnauta.Repositorie[] out of START_OBJECT token 
    Help Me! Please

  • #2
    Re: Deserialize object

    Looking at the raw JSON response from: http://github.com/api/v2/json/repos/show/schacon your code should look like this:

    Code:
    ResponseEntity<Repositories> responseEntity = restTemplate.exchange("http://github.com/api/v2/json/repos/show/schacon/", 
                    HttpMethod.GET, 
                    new HttpEntity<String>(headers), 
                    Repositories.class);
    
    Repositories repository = (Repositories) responseEntity.getBody();
    The <i>Repositories</i> would look like this:

    Code:
    public class Repositories {
        private ArrayList<Repository> repositories;
    
    	public ArrayList<Repository> getRepositories() {
    		return repositories;
    	}
    
    	public void setRepositories(ArrayList<Repository> repositories) {
    		this.repositories = repositories;
    	}
    }
    and the <i>Respository</i> object would contain values such as watchers, language, etc.
    Last edited by dutchman_mn; Feb 23rd, 2011, 01:00 PM. Reason: Redo example

    Comment

    Working...
    X