David Rogers
08/19/2024, 10:29 PMDavid Rogers
08/19/2024, 10:30 PMserializeJSONDavid Rogers
08/19/2024, 10:31 PMSerializeJSON( var=any, queryFormat=any, useSecureJSONPrefixOrCharset=any, compact=boolean );David Rogers
08/19/2024, 10:31 PMjava.util.Date to be serialized in a particular way.David Rogers
08/19/2024, 10:38 PMpackage lucee.runtime.converter;
public JSONConverter(boolean ignoreRemotingFetch, Charset charset) {
this(ignoreRemotingFetch, charset, JSONDateFormat.PATTERN_CF, true, null);
}
public JSONConverter(boolean ignoreRemotingFetch, Charset charset, String pattern)
public JSONConverter(boolean ignoreRemotingFetch, Charset charset, String pattern,
or use a particular "JSONConverter" with a particular "(date format) pattern"sknowlton
08/19/2024, 10:51 PMsknowlton
08/19/2024, 10:51 PMsknowlton
08/19/2024, 10:51 PMDavid Rogers
08/19/2024, 10:53 PMpublic static final String PATTERN_CF = "MMMM, dd yyyy HH:mm:ss Z";
so providing a custom pattern string to an instance of a native lucee serializer would be of equivalent performance; now, do they make it ergonomic to do so? Maybe not.sknowlton
08/19/2024, 10:55 PMsknowlton
08/19/2024, 10:55 PMDavid Rogers
08/19/2024, 11:03 PMpublic static String format(Date date, TimeZone tz, String pattern) {
tz = ThreadLocalPageContext.getTimeZone(tz);
String id = locale.hashCode() + "-" + tz.getID();
synchronized (sync) {
SoftReference<DateFormat> tmp = map.get(id);
DateFormat format = tmp == null ? null : tmp.get();
if (format == null) {
format = new SimpleDateFormat(pattern, locale);
format.setTimeZone(tz);
map.put(id, new SoftReference<DateFormat>(format));
}
return format.format(date);
}
}sknowlton
08/19/2024, 11:04 PMsknowlton
08/19/2024, 11:04 PMDavid Rogers
08/19/2024, 11:06 PMLarry Lopez
08/19/2024, 11:56 PMgavinbaumanis
08/20/2024, 12:20 AMTomy Saman
08/20/2024, 12:49 AMTomy Saman
08/20/2024, 12:49 AMTomy Saman
08/20/2024, 12:50 AMdswitzer
08/20/2024, 11:31 AMmap() to loop through and format the dates prior to serializing to convert them into a string of your desired format.
If you use an single instance of java.text.SimpleDateFormat to format the dates, it's pretty performant.
However, if the data is complex, deeply nested or you just generally need all dates formatted a specific way, then a custom serializer is probably the best choice.
Take a look at this thread too:
https://dev.lucee.org/t/serializejson-and-datetime/7887/4sknowlton
08/20/2024, 2:14 PMLarry Lopez
08/20/2024, 4:19 PM