RaghuNath - 2007-12-25

Hi I'm getting exception while invoking JSONObject.fromObject( new MyBean() )
I'm using following set of libs..
\commons-beanutils.jar
\commons-collections-3.2.jar
\commons-lang-2.3.jar
\commons-logging-1.1.1.jar
\ezmorph-1.0.4.jar
\json-lib-2.2-jdk15.zip
\commons-beanutils-bean-collections.jar
\commons-beanutils-core.jar
\junit4.4\junit-4.4.jar
=============================================
package com.visu.binbaz.server.json;
import static net.sf.json.test.JSONAssert.*;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;

public class JsonTest {
public static void main(String[] args) {
     MyJavaBean bean = new MyJavaBean(); 
     bean.setString( "JSON" ); 
     bean.setInteger( 1 ); 
     bean.setDooble( 2.0d ); 
     bean.setBool( true ); 
     JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( bean ); 
     assertEquals( "JSON", jsonObject.getString("string") );       
     assertEquals( 1, jsonObject.getInt("integer") );       
     assertEquals( 2.0d, jsonObject.getDouble("dooble"), 0d );       
     assertTrue( jsonObject.getBoolean("bool") ); 
}
}
=====================================================================
  class MyJavaBean { 
        private String string; 
        private int integer; 
        private double dooble; 
        private boolean bool;
        public String getString() {
            return string;
        }
        public void setString(String string) {
            this.string = string;
        }
        public int getInteger() {
            return integer;
        }
        public void setInteger(int integer) {
            this.integer = integer;
        }
        public double getDooble() {
            return dooble;
        }
        public void setDooble(double dooble) {
            this.dooble = dooble;
        }
        public boolean isBool() {
            return bool;
        }
        public void setBool(boolean bool) {
            this.bool = bool;
        } 
      
        // getters & setters 
     } 
      
    
=============================================
Exception in thread "main" net.sf.json.JSONException: java.lang.NoSuchMethodException: Property 'bool' has no getter method
    at net.sf.json.JSONObject._fromBean(JSONObject.java:947)
    at net.sf.json.JSONObject.fromObject(JSONObject.java:187)
    at net.sf.json.JSONArray.fromObject(JSONArray.java:192)
    at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:113)
    at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:84)
    at com.visu.binbaz.server.json.JsonTest.main(JsonTest.java:13)
Caused by: java.lang.NoSuchMethodException: Property 'bool' has no getter method
    at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1127)
    at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686)
    at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)
    at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:290)
    at net.sf.json.JSONObject._fromBean(JSONObject.java:922)
    ... 5 more