public JsonUtils()
{
jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(DateTime.class,
new JsonValueProcessor() {
public Object processArrayValue(Object arg0, JsonConfig arg1) {
throw new UnsupportedOperationException();
}
public Object processObjectValue(String arg0, Object arg1,
JsonConfig arg2) {
return new JSONRawString("Timeline.DateTime."
+ ((DateTime) arg1).toString());
}
});
jsonConfig.registerJsonBeanProcessor(JsonConstructor.class,
new JsonBeanProcessor() {
public JSONObject processBean(Object arg0, JsonConfig arg1) {
return (JSONObject) arg1.findJsonValueProcessor(
JsonConstructor.class).processObjectValue(null,
arg0, arg1);
}
});
jsonConfig.registerJsonValueProcessor(JsonConstructor.class,
new JsonValueProcessor() {
public Object processArrayValue(Object arg0, JsonConfig arg1) {
return processObjectValue(null, arg0, arg1);
}
public Object processObjectValue(String arg0, Object arg1,
JsonConfig arg2) {
JsonConstructor<?> constructor = (JsonConstructor<?>) arg1;
return new JSONRawString(constructor.getName()
+ "("
+ WebUtils.toString(JSONObject.fromObject(
constructor.getObject(), arg2)) + ")");
}
});
jsonConfig.registerJsonValueProcessor(RawString.class,
new JsonValueProcessor() {
public Object processArrayValue(Object arg0, JsonConfig arg1) {
throw new UnsupportedOperationException();
}
public Object processObjectValue(String arg0, Object arg1,
JsonConfig arg2) {
return new JSONRawString(((RawString) arg1).toString());
}
});
jsonConfig.registerJsonValueProcessor(RawString.class,
new JsonValueProcessor() {
public Object processArrayValue(Object arg0, JsonConfig arg1) {
throw new UnsupportedOperationException();
}
public Object processObjectValue(String arg0, Object arg1,
JsonConfig arg2) {
return new JSONRawString(((RawString) arg1).toString());
}
});
jsonConfig.registerJsonValueProcessor(Date.class,
new JsonValueProcessor() {
public Object processArrayValue(Object arg0, JsonConfig arg1) {
throw new UnsupportedOperationException();
}
public Object processObjectValue(String arg0, Object arg1,
JsonConfig arg2) {
Date date = (Date) arg1;
String dateString = new SimpleDateFormat("yyyy")
.format(date);
String retval = "Timeline.DateTime.parseGregorianDateTime(\""
+ dateString + "\")";
return new JSONRawString(retval);
}
});
jsonConfig.registerJsonValueProcessor(Date.class,
new JsonValueProcessor() {
public Object processArrayValue(Object arg0, JsonConfig arg1) {
throw new UnsupportedOperationException();
}
public Object processObjectValue(String arg0, Object arg1,