0

I'm coding a RESTful client for my AndroidApp. My rest webservice returns me a json and I pasrse it with springfreamwork into java class members. In this way my code is ok. I need to pass parameters from main activity to another one, so I implemented that class(Clinica.class see below) as PARCELABLE following the guide lines. Now app returns me this error

    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: libcore.net.http.ChunkedInputStream@41346758; 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: libcore.net.http.ChunkedInputStream@41346758; line: 1, column: 3]

this is my 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);
            }
        };

    }

and this is my Async call to make request

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

Any suggestions? Thanks in advance.

4

1 回答 1

3

The answer is simple: remove the constructor (also in parent class, if there is any inside) and everything will work! Maybe there is some annotation like @JsonIgnore, but it not work with constructors.

于 2012-12-30T12:58:52.140 回答