-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Child data views and maps #3130
Comments
I've been looking at this, and while any solution here shouldn't be too difficult to implement (I have a mostly working solution with tests for this specific case), I'm hesitant to commit any change to this because I think that the change to do this might be further ranging than first thought. The problem is indeed that lists (and maps, for that matter), allow for there to be child maps that do not get converted into So, the options I can think of are (in no particular order):
When I realised this, I was part way to implementing it the second way, but I'm not entirely convinced this is the best way to do it. I'm leaning towards option 3, where we just eliminate maps from the container, but whatever we do, it's going to be breaking, at least in terms of behaviour. |
I elect for the first option. Much like having to stick an artificial boolean key value on |
This allows the ConfigurateTranslator to determine when a DataView should be constructed instead of a map. During serialisation, any child DataViews that are detected will be have the special token $DataView applied to their configuration key. Upon deserialisation, this will be reversed, so a DataView, rather than a Map will be restored. This translator will walk down both maps and lists to ensure that DataViews are correctly constructed. Tests are included to attempt to ensure correctness. This will not affect existing serialised DataViews, as they will not have had the $DataView token applied to their key. Fixes SpongePowered/SpongeAPI#1543
I'd like to put out a remark here: When serializing data into configuration nodes, it is very likely that this is done to allow users to edit it in the text file. In that case, it is easy to overlook those private keys. Another thing I noticed is that if I use getMap on a key where I stored a DataView before, said DataView will automatically be converted to a map and returned. Wouldn't that be the most flexible option? |
My current work on this suffixes keys with However, I've been thinking about this and there are edge cases this won't account for, namely, if you have a list of I'm not sure I'm getting what you mean by your second point @Xfel - yes, getMap does that and it's how the translator currently works - which is why you always get maps back instead of |
Its been on my todo list for a while to remove maps and indeed any object from being stored in a dataview without being converted to a dataview. Right now another issues is that you can put any old non-serializable object into a dataview and it will just accept it, and then brick itself when you try and actually serialize the dataview. I think we want to catch those objects when they are inserted and ensure that a dataview contains only primative types, lists, and child dataviews. |
This allows the ConfigurateTranslator to determine when a DataView should be constructed instead of a map. During serialisation, any child DataViews that are detected will have an extra configuration key/value pair applied. Upon deserialisation, this will be detected and reversed, so a DataView, rather than a Map will be restored. This translator will walk down both maps and lists to ensure that DataViews are correctly constructed. Tests are included to attempt to ensure correctness. * Cleaned up some duplicate methods in ConfigurateTranslator Fixes SpongePowered/SpongeAPI#1543
This allows the ConfigurateTranslator to determine when a DataView should be constructed instead of a map. During serialisation, any child DataViews that are detected will have an extra configuration key/value pair applied. Upon deserialisation, this will be detected and reversed, so a DataView, rather than a Map will be restored. This translator will walk down both maps and lists to ensure that DataViews are correctly constructed. Tests are included to attempt to ensure correctness. This also allows non-maps to be deserialized, the item in question can be retrieved with the data query "value" - as there must be a DataView at the empty query point. * Cleaned up some duplicate methods in ConfigurateTranslator Fixes SpongePowered/SpongeAPI#1543, fixes #1142
Moving to common for the same reason as #3126 DataView implementation has been moved so this is an implementation issue. Note: it still needs to be tested after the configurate 3.7 PR |
so uh I'm pretty sure that as if my configurate 3.7 PR maps will now be translated as DataViews only, since I didn't really realize that was a distinction data views had :) at least for now translation is consistent, but it might still make sense to explicitly specify this type distinction. |
When putting a list of DataViews to a data view, serializing it using DataFormat.HOCON and reading it again, it becomes a list of Maps. This appears to be an issue with MemoryDataView: If the set method is passed a simple map, it is stored as a DataView internally. If passing a list of maps, however (which is what the HOCON translator does), it will remain a list of maps.
The text was updated successfully, but these errors were encountered: