-
Notifications
You must be signed in to change notification settings - Fork 34
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
copy_field
array of strings with a single value create internally no arrays
#621
Comments
copy_field
array of strings with a single valuecopy_field
array of strings with a single value are internally no arrays
copy_field
array of strings with a single value are internally no arrayscopy_field
array of strings with a single value create internally no arrays
E.g., with the following internal data: { "your": [ { "name": "max" }, { "name": "mo" } ] } Retrieving [ "max", "mo" ] As for your original |
This is also connected then: #604 and metafacture/metafacture-fix#92. Am I right? |
I would say this is not the same case. But I do not know if this makes a difference. While you are interested here in a single element of an array of objects: In my case you are interested in the array as a whole wether it be with a single element, multiple elements or none. Also how is catmandu behaving? |
https://github.com/TobiasNx/Catmandu-Testing/tree/master/ArrayHandling It seems that Catmandu is able to work with single and no value array of strings. |
One idea I have conceptually is, that you introduce a conditional control if the original value type is an array. |
While I see the conceptual point here, I don't quite see the practical problem. Why not add the And while it might be possible to preserve the original type (based on the path), I don't think it's worth the effort here. We already deviate from Catmandu since we need to specify the array marker in the fix (as in metafacture/metafacture-fix#240), and there is an easy solution, adding the array marker. Internally, the values are always in an array, and the array marker is used precisely to control if we want to output as an array or not. The empty array is a different topic, and we should fix that, but we have a separate issue for that (#195). |
Since I used the already established |
This again popped up. And I am still not sure why this is difficult: A copied array/list of strings with a single element is not copied as such, but copied as a simple string element. |
@blackwinter you already introduced a test if the elememt is an array here with metafacture/metafacture-fix@2427f2c: would it be possible to adjust the behaviour with single value arrays here too? |
Not sure why I am assigned here. I remember that @blackwinter suggested a solution that is not "universal" for every scenario in our meeting. @blackwinter do you remember? |
@blackwinter do you remember your suggestion how to approach this problem? Metafacture Fix should be able to handle arrays with a single index position as arrays:
|
I don't think there was such a suggestion. I probably said that it cannot work in the general case (because of nested paths and wildcards), but I don't see how we could solve it even for the simple cases. |
Thinking about this again there are three scenarios where single value arrays exist and I tested them:
This is not only relevant for JSON and YAML handling. It also can be for other testing purposes. Lists/arrays exist within the fix path model too even if the later serialization does not support lists or arrays. In my case I tried to |
When copying an array of strings that has a single value, fix seems not to copy it as an array but an simple string-element.
This is not spotted since fix outputs simple stringelements that have
[]
at the end of their name as arrays even if they are not handled as arrays fix-internally. I try to come up with an integration test for this.Here is an example for it.
This illustrates it even better:
It is disguised by the handling of the output by the json decoder.
This problem could be connected to: metafacture/metafacture-fix#116 and #616
It seems that array are not copied as arrays at all but each value individually. Therefore #616 empty arrays cannot be copied and arrays of strings with single values are not copied as simple string elements. With multiple values the behaviour therefore seems to be identical to the non-destructive behaviour of
copy_field/move_field
metafacture/metafacture-fix#116 .The text was updated successfully, but these errors were encountered: