-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
Non-string widget props with defaults are converted to strings when stored in JSONDB #2990
Comments
I think I've found the root cause, it's here: I don't know if it's possible to get Gson to serialize the same field to different types, it sounds "problematic". So, since the field is defined as a string, everything becomes a string. It might be possible to keep it as an Object in the DTO class and write some "type adapter" or something that could handle it - I'm really not that well versed in Gson to know exactly how this could be solved. Alternatively, there could be some logic that looked at the I would maybe think that this problem is more general than just the UI though, as it seems like this problem applies to all configuration parameter storage. |
What if you don't put the default value in hyphens ? That's the way I normaly do. |
The hyphen is there just because it's the first field in the array entry. It marks where a new parameter begins. I can rearrange the order so that default isn't the first, and thus the hyphen is on some other field, but because the JSONDB will arrange the fields alphabetically, unless you have a field like I'm pretty sure that this problem has nothing to do with the hyphen, it is a result of the deserialization in Core which "forces" the |
The problem
I don't know if this problem is actually in MainUI or in Core, but I'm posting here first. The problem probably doesn't just apply to widgets, but that's where I've observed it.
When you define a prop for a widget that is a boolean or a number and which has a default, the type isn't respected when the widget is stored, and everything seems to be converted to strings - which causes widgets to misbehave once retrieved from storage.
Example definition:
After storing and reopening the widget, this has "magically" been transformed to
When using this in an expression like
=props.showLCD?
, the default will in effect be "true" because it's not an empty string. Before the widget is stored (and the quotes added), the evaluation works correctly. To make it behave correctly after retrieval, one must instead do something likeprops.showLCD&&props.showLCD!='false'?
. The issue is the same with numbers, where various bugs appear after retrieving the widget from storage.By peeking in the JSONDB, I can see that the default values have already been converted to string before being stored, so it looks like the problem is somewhere "on the way to storage" - not during retrieval:
As can be seen,
required
is stored correctly and doesn't suffer from this issue.It seems to me that the
type
should be taken into account when thedefault
is converted, and I'm starting to realize that this problem probably is in Core.The text was updated successfully, but these errors were encountered: