-
Notifications
You must be signed in to change notification settings - Fork 364
DateString returning unexpected format via API #1636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello @charlie-s, thank you for reporting this issue. To be honest, I am not sure what should be the right behavior here :( |
Thanks for posting, @bajtos. This issue was quite difficult to track down, I had to read up on the entire history of DateString conversations and wrap my head around where it landed. It seemed like the solution was already implemented and everything was perfect – then suddenly I got to this last stage and had to scratch my head! Perhaps the |
Maybe {
"number": 1111,
"date_placed": "2018-10-08",
"id": 1
} My biggest concern about changing the implementation of On the other hand, I don't see how to current behavior (JSON output) can be useful to anybody, especially since this value cannot be fed back to DateString - i.e. a rountrip "get value from DB" and "save the same value back" will fail (if my understanding is correct). I am proposing to introduce a feature flag - a static property on Alternatively, instead of implementing a feature flag in juggler, maybe you can override // server/boot/fix-datastring-json.js
const DateString = require('loopback-datasource-juggler/lib/date-string.js');
module.exports = function(app) {
DateString.prototype.toJSON = function() {
return this.toString();
};
}; I think this may be the best solution for LB2/LB3 applications. For LoopBack 4, I'd like us to address date-only strings more holistically, see loopbackio/loopback-next#1966. What do you think? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
Description/Steps to reproduce
DateString
property:For example, POST the following request body to
https://loopback-date-strings.herokuapp.com/api/Invoices
)Link to reproduction sandbox
https://loopback-date-strings.herokuapp.com
Expected result
Response body is unescaped JSON and contains the date as a string.
Additional information
Response body contains escaped JSON and contains the date within this escaped JSON, as a property of
when
:Perhaps the formatting of the
DateString
property is expected, but it is not clear to me why this data type behaves this way as I've never seen another property come over from my LoopBack API's as an escaped JSON string.The DateString type overrides the native
toJSON
implementation with this:Does anyone know why? Pinging @kjdelisle since I believe he wrote this, and #1356 (comment) which is the only discussion I can find related to this.
The text was updated successfully, but these errors were encountered: