This repository has been archived by the owner on Aug 8, 2020. It is now read-only.
DropkicK Json List matched to an empty C# List #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem statement
While using DropkicK to manage the deployment of a C# project (.Net 4.5), we use Json files to describe deployment settings. Those are bound at run-time, by the Magnum library, against custom C# class files (extending dropkick.Configuration.Dsl.Deployment).
Unfortunately, JSON lists were bound to an empty List at runtime.
Magnum internal details
JsonValueProvider
Recursive calls in the JsonValueProvider, when reading the Json content, were wrongly linking each array item into a separate {key, value} pair within its internal dictionary.
ListBinder / EnumerableBinderBase
On the other end, the EnumerableBinderBase was binding an empty list to the custom c# deployment settings object, regardless of the context property value (that is, the list content).
Example
Considering the JSON sample, the internal dictionary of JsonValueProvider would have the following wrong content:
The correct content should be:
Therefore, at binding time (InstanceBinderContext), the binder would look to match the C# property ERPBinariesGroups to a context unable to match its request as it only knows the properties ERPBinariesGroups[i].
Few comments
Took me a while to figure the whole thing out. I don't recommend using my commits "as is" to fix the issue as I have disabled the rake tests task and hardcoded the string type for the List being recursively constructed in the JsonParser.
I looked at making the whole thing generic and a bit cleaner but that's the best I can do for the time being without breaking half of the API.
Hope this helps,
Pierre.