Skip to main content

Posts

Showing posts from July, 2009

Json-lib vs Hibernate

Subtitle: java.util.Date vs java.sql.Timestamp One of my projects has a data path where Hibernate entities are converted to Json objects by using json-lib . I have some special formatters, e.g. for Date objects for having an easy readable format instead of this: {"date":1,"day":4,"hours":1, "minutes":0,"month":0,"nanos":0, "seconds":0,"time":0,"timezoneOffset":-60,"year":70} A JsonConfig object can be suited by special formatters which later will be given to the fromObject method: JsonConfig cfg = new JsonConfig(); cfg.registerJsonValueProcessor( java.util.Date.class, new JsonValueProcessor() { private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd"); public Object processArrayValue(Object value, JsonConfig c) { return format((Date)value); } public Object processObjectValue( String key, Object v, JsonConfig c) { return format(