Project

General

Profile

Feature #1588

serializeDate option

Added by Robert Ivens 5 months ago. Updated 5 months ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
10/04/2023
Due date:
% Done:

0%

Estimated time:
Browser (if web client):

Description

For my OpenAPI router framework I do a lot of validating, including date-only and date-time formats.
But it seems Velocity already converts these values to Date objects. So maybe we could have a serializeDate=true/false (default to true) option config.json so the string is untouched.
I can convert the strings myself after validation to dates if needed.

History

#1

Updated by Patrick Talbot 5 months ago

So it's more about de-serializing (or not) rather than serializing, right?
Because if you have a Date object in your context, in JSON it will have to be serialized, but that would be the programmer's responsability.

#2

Updated by Patrick Talbot 5 months ago

  • Status changed from New to Resolved

See v3.6.4

I've added a parameters to the fromJSON() method (beware that there was already an optional boolean parameter "convertHtmlEntities" - false by default - which when set to true was transforming &/</> into their character equivalent (&,<,>)) so the full signature is
- fromJSON(string, [convertHtmlEntities], [convertDate])

I've also added a "deserializeDate" property in config.json at the solution level and the service level, this is used for the return of services called with invokeService(), it performs the same change of behavior (with a default of true). This can be set at the solution level for all services, and/or at the service level (in the "services" node) - overriding the solution level value.

#3

Updated by Patrick Talbot 5 months ago

In v3.6.5, I've added a default report parameters "deserializeDate".

So. you can simply set that default parameters at solutionOpen, like this:
plugins.VelocityReport.addDefaultReportParameter("deserializeDate", false);

And all subsequent calls to fromJSON() will not attempt to deserialize the dates...

Also available in: Atom PDF