-
Notifications
You must be signed in to change notification settings - Fork 10.3k
JSON Patch: Support real extension scenarios without copying heaps of code #2743
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
Comments
I just deleted my previous comment about considering the path when choosing the adapter. In fact, the path should not factor into that decision. The path and its segments should only affect individual operations performed on the chosen adapter. |
As an alternative to above |
Thanks for contacting us, @HappyNomad. |
@mkArtakMSFT We already went through a lot of discussion on this and, as far as I can tell, the changes have already been made to the code base. Are you planning to roll those changes back? |
Microsoft.AspNetCore.JsonPatch
is an important library in my projects. To be useful, however, I must tweak itsApplyTo
behavior as described at #2432. Judging from others' issues I've read, what I'm doing isn't unusual. It seems to be a common need. I'm thankful that at least some extension point exists, but the current extensibility mechanism is cumbersome. The API should be improved.I slightly diverge from the spec in my scenario, but the extensibility improvement would provide benefit beyond my use case.. One may need to patch objects of types not specifically supported by the library. While the patch document adheres to the spec, one may need to apply it to object types that the library couldn't anticipate. Those target object types could belong to a proprietary database engine, for example.
IObjectAdapter
was created to facilitate customization from outside the library. This intent is apparent since (1) it's in the public API, and (2) it's not used internally within the library. Judging by the large amount of code duplication necessary to use it, however, it seems it wasn't tested with a real-world customization like #2432. To customize a few lines of code, I had to copy nine files. (They were ClosedGenericMatcher.cs, ConversionResultProvider.cs, ErrorReporter.cs, IAdapter.cs, ListAdapter.cs, ObjectAdapter.cs, ObjectVisitor.cs, PocoAdapter.cs, and Resources.Designer.cs.) This duplication poses the danger that (1) the copies become out-of-date with their original versions, and (2) the customized patch behavior overly diverges from the JSON Patch spec.Rather than let the existing API stagnate and this problem fester, I propose the following. Solicit additional real-world extension scenarios from the community. Then take all scenarios into consideration and replace or augment the
IObjectAdapter
extension point with an API that allows us to cleanly extendJsonPatchDocument
.As for what specific API change to make, I offer the following initial suggestion. Replace the
IObjectAdapter
extension point with apublic interface IAdapterFactory
. It defines a single method with the signatureIAdapter Create( object target, JsonContract jsonContract )
. UseIAdapterFactory
inObjectVisitor
's privateSelectAdapater
method.The text was updated successfully, but these errors were encountered: