1

This is my POJO class:

public class OrdineIngressi {

    private Integer spettacolo;
    private Integer settore;
    private Integer pv;
    private List<OrdineIngresso> ingressi=new ArrayList<OrdineIngresso>();

    public OrdineIngressi(Integer spettacolo, Integer settore, Integer pv,
            List<OrdineIngresso> ingressi) {
        super();
        this.spettacolo = spettacolo;
        this.settore = settore;
        this.pv = pv;
        this.ingressi = ingressi;
    }



    public OrdineIngressi() {
        super();
    }



    public Integer getSpettacolo() {
        return spettacolo;
    }
    public void setSpettacolo(Integer spettacolo) {
        this.spettacolo = spettacolo;
    }
    public Integer getSettore() {
        return settore;
    }
    public void setSettore(Integer settore) {
        this.settore = settore;
    }   
    public Integer getPv() {
        return pv;
    }
    public void setPv(Integer pv) {
        this.pv = pv;
    }
    public List<OrdineIngresso> getIngressi() {
        return ingressi;
    }
    public void setIngressi(List<OrdineIngresso> ingressi) {
        this.ingressi = ingressi;
    }



    public class OrdineIngresso {

        private Integer tipoingresso;
        private Integer abbonamento;
        private int numero;
        private Integer[] posti;

        public OrdineIngresso() {
            super();
        }



        public OrdineIngresso(Integer tipoingresso, Integer abbonamento,
                int numero, Integer[] posti) {
            super();
            this.tipoingresso = tipoingresso;
            this.abbonamento = abbonamento;
            this.numero = numero;
            this.posti = posti;
        }
        public Integer getTipoingresso() {
            return tipoingresso;
        }
        public void setTipoingresso(Integer tipoingresso) {
            this.tipoingresso = tipoingresso;
        }
        public Integer getAbbonamento() {
            return abbonamento;
        }
        public void setAbbonamento(Integer abbonamento) {
            this.abbonamento = abbonamento;
        }
        public Integer[] getPosti() {
            return posti;
        }
        public void setPosti(Integer[] posti) {
            this.posti = posti;
        }
        public int getNumero() {
            return numero;
        }
        public void setNumero(int numero) {
            this.numero = numero;
        }   


    }   

}

This is the ajax input:

{"spettacolo":1,"settore":1,"pv":1,"ingressi":[{"tipoingresso":1,"abbonamento":null,"numero":1,"posti":[]}]}

When the Controller tries to unmarshal a json input I got this:

nested exception is org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.bean.OrdineIngressi$OrdineIngresso]: can not instantiate from JSON object (need to add/enable type information?)

Why? There is a default constructor!

6
  • Why aren't you using english names? Commented Jun 24, 2014 at 9:36
  • ...Because I'm not english. But I think here names are not so important, consider it something like code obfuscation ;-). Commented Jun 24, 2014 at 9:37
  • 2
    @AdamArold Perhaps because he's italian? Does it matter? Commented Jun 24, 2014 at 9:37
  • I think hames are really important and they are conventionally english. For example I cannot understand the objects you are using in your code thus cannot answer your question. Commented Jun 24, 2014 at 9:40
  • Luckily, in this particular matter, one did not need to understand the (spoken) language to spot the error. Commented Jun 24, 2014 at 9:48

1 Answer 1

2

You're almost there, you just need to make your inner class static:

...
    public static class OrdineIngresso {
        private Integer tipoingresso;
        ...
    }

IIRC it has to do with the fact that a non-args inner class constructor really isn't non-args and thus jackson doesn't have a general manner for instantiating these non-static inner classes.

Cheers,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.