2012-08-29 3 views
0

AndroidApp 용 RESTful 클라이언트를 코딩하고 있습니다. 내 휴식 webservice 내게 json을 반환하고 나는 자바 클래스 멤버로 springfreamwork와 함께 그것을 pasrse. 이 방법으로 내 코드는 괜찮습니다. 주요 활동에서 다른 활동으로 매개 변수를 전달해야하므로 안내 선 다음에 PARCELABLE로 해당 클래스 (Clinica.class는 아래 참조)를 구현했습니다. 이제 응용 프로그램은 날이 오류org.codehaus.jackson.map.JsonMappingException : 형식에 적합한 생성자가 없습니다.

org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: No suitable constructor found for type [simple type, class it.stasbranger.clinigomobile.model.Clinica]: can not instantiate from JSON object (need to add/enable type information?) 
at [Source: [email protected]; line: 1, column: 3]; nested exception is org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class it.stasbranger.clinigomobile.model.Clinica]: can not instantiate from JSON object (need to add/enable type information?) 
at [Source: [email protected]; line: 1, column: 3] 

반환이 내 Clinica.class

public class Clinica implements Parcelable { 

     @JsonProperty 
     private Integer idclinica; 
     @JsonProperty 
     private String nome; 
     @JsonProperty 
     private Long dataRegistrazione; 
     @JsonProperty 
     private Long version; 
     @JsonProperty 
     private String referente; 
     @JsonProperty 
     private String indirizzo; 
     @JsonProperty 
     private String cap; 
     @JsonProperty 
     private String telefono; 
     @JsonProperty 
     private String email; 
     @JsonProperty 
     private String sitoWeb; 
     @JsonProperty 
     private Boolean abilitata; 
     @JsonProperty 
     private Integer valutazione; 
     @JsonProperty 
     private Double rank; 
     @JsonProperty 
     private String nomeFatturazione; 

     //getters and setters 
      ....... 

     public Clinica (Parcel p){ 
      boolean[] booleans = new boolean[1]; 

      this.cap=p.readString(); 
      this.email=p.readString(); 
      this.indirizzo=p.readString(); 
      this.nome=p.readString(); 
      this.nomeFatturazione=p.readString(); 
      this.referente=p.readString(); 
      this.sitoWeb=p.readString(); 
      this.telefono=p.readString(); 

      this.idclinica=p.readInt(); 
      this.valutazione=p.readInt(); 

      this.dataRegistrazione=p.readLong(); 
      this.version=p.readLong(); 

      this.rank=p.readDouble(); 

      p.readBooleanArray(booleans); 
      this.abilitata=booleans[0]; 
     } 

     public int describeContents() { 
      return 0; 
     } 

     public void writeToParcel(Parcel dest, int flags) { 
      boolean[] booleans = new boolean[1]; 
      Arrays.fill(booleans, abilitata); 
      dest.writeString(cap); 
      dest.writeString(email); 
      dest.writeString(indirizzo); 
      dest.writeString(nome); 
      dest.writeString(nomeFatturazione); 
      dest.writeString(referente); 
      dest.writeString(sitoWeb); 
      dest.writeString(telefono); 
      dest.writeInt(idclinica); 
      dest.writeInt(valutazione); 
      dest.writeLong(dataRegistrazione); 
      dest.writeLong(version); 
      dest.writeDouble(rank); 
      dest.writeBooleanArray(booleans); 
     } 

     public static final Parcelable.Creator<Clinica> CREATOR = new Creator<Clinica>() { 

      public Clinica[] newArray(int size) { 
       return new Clinica[size]; 
      } 

      public Clinica createFromParcel(Parcel source) { 
       return new Clinica(source); 
      } 
     }; 

    } 

이며,이 요청

...... 
Clinica data[] = restTemplate.getForObject(urls[0], Clinica[].class, vars); 

어떤 제안을 내 비동기 호출이 무엇입니까? 미리 감사드립니다.

답변

3

대답은 간단합니다. 생성자를 제거하고 (내부 클래스가있는 경우 상위 클래스에서도) 모든 것이 작동합니다! 어쩌면 @JsonIgnore와 같은 일부 주석이 있지만 생성자와 작동하지 않을 수 있습니다.

+0

왜 인수 컨스트럭터를 제거하거나 인수가없는 생성자를 추가해야하는지 알 수 있습니까? –

+0

어, 오랜 시간이 걸리므로 잭슨은 자체 생성자를 추가합니다. 정의 된 잭을 가지고 있기 때문에 사용할 잭이 없습니다. [this post] (http://www.cowtowncoder.com/blog/archives/2011/07/entry_457.html)를보십시오. – shmoula

관련 문제