-
Notifications
You must be signed in to change notification settings - Fork 176
ObjectDifferBuilder question #99
Copy link
Copy link
Closed
Description
I'm using the ObjectDifferBuilder to inject my own custom collection differ and a couple of other custom differs. This wound up being more code than I thought. I'm wondering if there's an easier way to modify the default builder apart from what I'm doing below.
// I don't see how to get all of the default differs and be able to
// just add my own in place where I need it.
ObjectDifferBuilder b = ObjectDifferBuilder.startBuilding();
final DifferProvider differProvider = new DifferProvider();
// notice all of the casts below.... the builder I'm using
// provides access to all of the objects I need to construct the
// differs but it returns them as their interfaces while the
// actual constructors accept either the class or a different interface.
final DifferDispatcher differDispatcher = new DifferDispatcher(
differProvider,
(CircularReferenceDetectorFactory)b.circularReferenceHandling(),
(CircularReferenceExceptionHandler)b.circularReferenceHandling(),
(IsIgnoredResolver)b.inclusion(),
(IsReturnableResolver)b.filtering());
// the default collection differ I want to use as a fallback if the collection type
// isn't what I'm looking for
CollectionDiffer fallback = new CollectionDiffer(differDispatcher,
(ComparisonStrategyResolver) b.comparison());
differProvider.push(new BeanDiffer(differDispatcher,
(IsIntrospectableResolver)b.introspection(),
(IsReturnableResolver)b.filtering(),
(ComparisonStrategyResolver)b.comparison(),
(IntrospectorResolver)b.introspection()));
// my first custom differ. It delegates to a fallback if the primary differ doesn't handle the type
differProvider.push(new DelegatingCollectionDiffer(
Arrays.<Differ>asList(new MyTypeOfObjectDiffer(differDispatcher)), fallback));
differProvider.push(new MapDiffer(differDispatcher,
(ComparisonStrategyResolver)b.comparison()));
// here's another custom differ
differProvider.push(new AnotherOfMyCustomDiffers(differDispatcher));
differProvider.push(new PrimitiveDiffer(
(PrimitiveDefaultValueModeResolver) b.comparison()));
// all of the above just to get my differ registered
objectDiffer = new ObjectDiffer(differDispatcher);
Just to be clear, everything above works as expected, I'm just confused as to why I need all of these casts or all of this code just to add two new differs where I want them in the default list.
Reactions are currently unavailable