Results 1 to 2 of 2

Thread: [PROBLEM SPRING ANDROID] deserialize object

  1. #1
    Join Date
    Dec 2007
    Posts
    7

    Unhappy [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. #2

    Default 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 at 01:00 PM. Reason: Redo example

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •