Bug with Dates
Brought to you by:
aalmiray
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!
Logged In: NO
Sorry.
This REALLY throws an exception:
JSONObject.fromObject(new java.sql.Date(1,1,1999))
Not the first!
Logged In: YES
user_id=1192026
Originator: NO
Wouldn't a JsonBeanProcessor or JsonValueProcessor help you ?
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.
Logged In: YES
user_id=1192026
Originator: NO
CLOSED. will add a FR to change JsDate*Processor to handle java.sql.Date
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!
Logged In: YES
user_id=1192026
Originator: NO
The processor is available in 2.1-SNAPSHOT, here is the FR
http://sourceforge.net/tracker/index.php?func=detail&aid=1785314&group_id=171425&atid=857931
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
Could you please send some sample code along with the stacktrace? thank you!
Andres