I'm trying to prevent certain properties of a DTO from being patched when calling patch.ApplyTo(object, adapter)
. My current plan is to put a custom attribute onto properties that are to be ignored, and, using that adapter, only allow operations to go through if the path used in that operation does not contain a property name that should be ignored. Eg.
class CustomAdapter : IObjectAdapter
{
public void Add(Operation operation, object objectToApplyTo)
{
if (pathIsValid(operation.path)) {
// Actually do the adding somehow
}
}
}
Maybe this is a silly question, but I cannot find any info on how to do the actual adding part. In fact, I can't find any references at all on how this (IObjectAdapter) is supposed to be used with JsonPatch, other than there being an overload to pass an adapter in.
Is there some way I can call on the default implementation of any given operation? operation.Apply()
exists, but it requires an adapter as its second parameter--what is the 'default adapter' of JsonPatch? Or is there a better/built-in way of going about this entirely?