Exception thrown on all Date fields

  • marcj12

    marcj12 - 2007-06-23

    Hi, I'm using json-lib in my spring/oracle app.  I use POJO's with the usual accessors.  When I try to convert a bean such as

        public class foo {
            private int a;
            private java.util.Date startDate;
            public Date getStartDate() {
                return startDate;
    into JSON, using:

        JSONObject jsonFoo = JSONObject.fromObject(foo);

    json-lib throws an exception on the first Date field it hits, consistently, on any class containing a Date field.  I've stepped through it, and specifically, it throws an exception when calling Date.getHours(), in JSONObject.fromBean(), while iterating through all the fields of the Date object. 
    When it hits the hours field of the date, it throws an exception at
        Object value = PropertyUtils.getProperty( bean, key );

    It's an InvocationTargetException, which points to an IllegalArgumentException. 
    I can't find anything else wrong with it.

    The Date itself is not null.  However it is a simple date; the time is 00:00:00.  I would not expect this to be a problem. 

    I also noticed many of the Date methods are deprecated, including getHours().  I'm using jdk 1.5.0_11.

    Any ideas?

    • aalmiray

      aalmiray - 2007-06-24

      That's definitely very strange... which version of json-lib are you using?

  • Pedro

    Pedro - 2010-04-08

    Hi, i have the same problem using: json-lib-1.0b1-jdk13.jar
    WebSphere Studio Application Developer (Windows)  Version: 5.1.2
    JDK 1.3
    My code: net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(map);
    Map is a HashMap with ArrayLIst., the beans contains fields java.sql.Date.
    The error is "net.sf.json.JSONException: java.lang.reflect.InvocationTargetException"
    I download the sourcecode, and trace the application. The result : the method JSONObject.fromObject, read all the methods from the beans, but include the deprecated method. (getHours)

      public static JSONObject fromBean( Object bean, String excludes, boolean ignoreDefaultExcludes )
                     Class type = pds_.getPropertyType();
                   if( pds.getReadMethod() != null ){
                      Object value = PropertyUtils.getProperty( bean, key );   (this line throw error)

    Sorry for my English, I speak Spanish.


  • Pedro

    Pedro - 2010-04-09

    Hi again, i try with json-lib-2.3-jdk13.jar, but I had the same error.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks