Menu

#43 Bug with Dates

open
aalmiray
None
5
2009-04-08
2007-08-30
Anonymous
No

This throws an exception:

JSONObject.fromObject(new java.util.Date(1,1,1999))

Its a problem because all date fields from beans
are populated from database through getDate() from
ResultSet, and its type is java.sql.Date, not
java.util.Date.

You can solve it in this way:

java.sql.Date bad = new java.util.Date(1,1,1999);
java.util.Date good = new java.util.Date(bad.getTime());

Please, add the necessary code in JSONObject, method
"public static JSONObject fromObject( Object object )"

Thanks!

Discussion

  • Nobody/Anonymous

    Logged In: NO

    Sorry.

    This REALLY throws an exception:

    JSONObject.fromObject(new java.sql.Date(1,1,1999))

    Not the first!

     
  • aalmiray

    aalmiray - 2007-08-30

    Logged In: YES
    user_id=1192026
    Originator: NO

    Wouldn't a JsonBeanProcessor or JsonValueProcessor help you ?

     
  • aalmiray

    aalmiray - 2007-08-31
    • assigned_to: nobody --> aalmiray
     
  • aalmiray

    aalmiray - 2007-08-31

    Logged In: YES
    user_id=1192026
    Originator: NO

    You may register a JsonBeanProcessor or a JsonValueProcessor to handle java.sql.Date.
    The exception is caused by java.sql.Date when some properties are accessed,

    public int getHours() {
    throw new java.lang.IllegalArgumentException();
    }

    Perhaps I can add a JsSqlDateProcessor to the lib, but definitely this is not a bug.

     
  • aalmiray

    aalmiray - 2007-08-31

    Logged In: YES
    user_id=1192026
    Originator: NO

    CLOSED. will add a FR to change JsDate*Processor to handle java.sql.Date

     
  • aalmiray

    aalmiray - 2007-08-31
    • status: open --> closed
     
  • Nobody/Anonymous

    Logged In: NO

    I'm sorry.
    It seems to be a bug, but you're right.
    Until next release, I will use a bean procesor.

    Thanks!

     
  • Nobody/Anonymous

    • status: closed --> open
     
  • aalmiray

    aalmiray - 2007-08-31
    • status: open --> closed
     
  • Nobody/Anonymous

    I'm using json-lib 2.2.1, and there still is an issue where json-lib gets java.util.Date and java.sql.Date mixed up.

    I have a class Foobar with a property 'java.util.Date date', but if I try to convert an instance of Foobar to a JSONObject, the exception thrown refers to 'java.sql.Date' (which I have never ever used anywhere)
    Registering a JsDateJsonBeanProcessor for java.util.Date doesn't help

     
  • Nobody/Anonymous

    • status: closed --> open
     
  • aalmiray

    aalmiray - 2009-04-08

    Could you please send some sample code along with the stacktrace? thank you!

    Andres

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.