String escapedFormattedString = "";
boolean isJsonNull = false;
// Prepare a Json string representing the current value.
DateValue dateValue;
TimeOfDayValue timeOfDayValue;
if((value == null) || (value.isNull())) {
valueJson.append("null");
isJsonNull = true;
}
else {
switch(type) {
case BOOLEAN:
valueJson.append(((BooleanValue) value).getValue());
break;
case DATE:
valueJson.append("Date(");
dateValue = (DateValue) value;
valueJson.append(dateValue.getYear()).append(",");
valueJson.append(dateValue.getMonth()).append(",");
valueJson.append(dateValue.getDayOfMonth());
valueJson.append(")");
this.appendDate(valueJson);
break;
case NUMBER:
valueJson.append(((NumberValue) value).getValue());
break;
case TEXT:
valueJson.append("\"");
valueJson.append(EscapeUtil.jsonEscape(value.toString()));
valueJson.append("\"");
break;
case TIMEOFDAY:
valueJson.append("[");
timeOfDayValue = (TimeOfDayValue) value;
valueJson.append(timeOfDayValue.getHours()).append(",");
valueJson.append(timeOfDayValue.getMinutes()).append(",");
valueJson.append(timeOfDayValue.getSeconds()).append(",");
valueJson.append(timeOfDayValue.getMilliseconds());
valueJson.append("]");
break;
case DATETIME:
calendar = ((DateTimeValue) value).getCalendar();
valueJson.append("Date(");