SORU
2 EKİM 2011, Pazar


JsonMappingException: uygun yapıcı türü bulundu [basit türü, sınıfı ]: JSON nesne oluşturmak mümkün değil

JSON istek ve^ işlemek için çalışırken aşağıdaki hatayı alıyorum .

org.codehaus.jackson.göster.JsonMappingException: uygun yapıcı tür basit tür, sınıf com.myweb.ApplesDO]: oluşturmak değil nesne (etkinleştir/tür bilgi eklemek için ihtiyacınız var?) JSON dan

Burada göndermek için çalışıyorum JSON:

{
  "applesDO" : [
    {
      "apple" : "Green Apple"
    },
    {
      "apple" : "Red Apple"
    }
  ]
}

Kontrolör , aşağıdaki yöntem imzası var

@RequestMapping("showApples.do")
public String getApples(@RequestBody final AllApplesDO applesRequest){
    // Method Code
}

AllApplesDO ApplesDO bir sarıcı

public class AllApplesDO {

    private List<ApplesDO> applesDO;

    public List<ApplesDO> getApplesDO() {
        return applesDO;
    }

    public void setApplesDO(List<ApplesDO> applesDO) {
        this.applesDO = applesDO;
    }
}

ApplesDO

public class ApplesDO {

    private String apple;

    public String getApple() {
        return apple;
    }

    public void setApple(String appl) {
        this.apple = apple;
    }

    public ApplesDO(CustomType custom){
        //constructor Code
    }
}

JACKSON sublclasses için JAVA nesneleri JSON dönüştürmek mümkün olduğunu düşünüyorum. JACKSON için yapılandırma parametreleri ile yardım JAVA Nesneleri JSON dönüştürmek için lütfen!!! Bahar Çerçeve kullanıyorum

EDİT: yukarıdaki örnek sınıf içinde bu soruna neden olan büyük hata Dahil - Lütfen çözüm için cevap kabul bak.

CEVAP
2 EKİM 2011, Pazar


Sonunda sorunun ne olduğunu anladım. Şüphelendiğim gibi Jackson yapılandırma sorunu değil.

Aslında sorun olduApplesDOSınıf:

public class ApplesDO {

    private String apple;

    public String getApple() {
        return apple;
    }

    public void setApple(String apple) {
        this.apple = apple;
    }

    public ApplesDO(CustomType custom) {
        //constructor Code
    }
}

Özel bir kurucu sınıfın varsayılan kurucu yapmak için tanımlanmıştır. Kukla bir kurucu tanıtan gitmek hata yaptı:

public class ApplesDO {

    private String apple;

    public String getApple() {
        return apple;
    }

    public void setApple(String apple) {
        this.apple = apple;
    }

    public ApplesDO(CustomType custom) {
        //constructor Code
    }

    //Introducing the dummy constructor
    public ApplesDO() {
    }

}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • iZAPPA

    iZAPPA

    16 Temmuz 2010
  • Matt Steffanina

    Matt Steffan

    1 EYLÜL 2011
  • Stevie

    Stevie

    2 Mayıs 2010