-
Notifications
You must be signed in to change notification settings - Fork 105
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
Warnings about deprecated fields due to JSON.stringify
usage
#308
Comments
Very nice catch. |
I'm also don't know a lot about js. I think excluding fileds by default might be a bit risky since in the future Google Maps Api could add fields with the same names, or some customers might actually need those fields there. I think a better approach would be to have an option of controling serialization behaivour that would allow avoiding such cases if needed. For example define wrapper over const extendepbleStringify = function (obj, replacer, space) {
if (window.blazorGoogleMapsBeforeStringify) {
obj = window.blazorGoogleMapsBeforeStringify(obj);
}
return JSON.stringify(obj, replacer, space);
}; Then customers would be able to define their funtion to exclude fields that they have problem with, like this: const removeDepricatedFieldsFromObject = function (obj) {
if ('place_id' in obj) {
delete obj.utc_offset
}
if ('opening_hours' in obj) {
const hours = obj.opening_hours
delete hours.open_now
}
}
const removeDepricatedFields = function (obj) {
if (Array.isArray(obj)) {
for (const element of obj) {
removeDepricatedFields(element)
}
} if (typeof obj === 'object' && obj !== null) {
removeDepricatedFieldsFromObject(obj)
}
}
window.blazorGoogleMapsBeforeStringify = function (obj) {
removeDepricatedFields(obj);
return obj;
}; This would also alow flexibility to adapt to future API changes and should not degrade performance too much for people who are not interested in excluding fields since warnings do not apear in most of the scenarios. I'm not sure how common this approach are in js or is there are a nicer way, but if that's something you thin acceptable I would be happy to contribute this change. I'm also open for any other suggestions. |
My initial issue for google API was closed as "by design", so I've created another one with alternative suggestion https://issuetracker.google.com/issues/323230578 |
Sorry but i am on workation, so will take a look till 18 for sure. Especially it is not critical. |
No problem at all. Thank you for letting me know. I hope you'll have a great workation! |
I'm getting errors in browser console about using depricated fields like
utc_offset
andopen_now
that I'm not actually using.I think they are caused by
JSON.stringify
of PlaceDetails objects in theBlazorGoogleMaps/GoogleMapsComponents/wwwroot/js/objectManager.js
Line 528 in bab99d5
It would be very helful to have an option to configure some exclusion list to skip fields during serialization. Usually Google Maps API allows to select what fields you want in order to avoid those problems, but it's not the case for SearchBox for example.
I've also created issue for the SearchBox to allow selecting fields, but looks like the won't act on it https://issuetracker.google.com/issues/322623560
Problem could be reproduced using following code:
So far the best workaround I was able to come up with is following hack, but I would really line to have better option to just exlude fields in the
GoogleMapsComponents/wwwroot/js/objectManager.js
instead of replacingJSON.stringify
for everybody. (udpated snipnet after some more testing)The text was updated successfully, but these errors were encountered: