MarshallingStubUtils { public static Object stubDMNResult(Object result, Function<Object, Object> stubbingWrapper) { if (result instanceof DMNContext) { Map<String, Object> stubbedContextValues = new HashMap<>(); for (Entry<String, Object> kv : ((DMNContext) result).getAll().entrySet()) { stubbedContextValues.put(kv.getKey(), stubDMNResult(kv.getValue(), stubbingWrapper)); } return MapBackedDMNContext.of(stubbedContextValues); } else if (result instanceof Map<?, ?>) { Map<Object, Object> stubbedValues = new HashMap<>(); for (Entry<?, ?> kv : ((Map<?, ?>) result).entrySet()) { stubbedValues.put(kv.getKey(), stubDMNResult(kv.getValue(), stubbingWrapper)); } return stubbedValues; } else if (result instanceof List<?>) { List<?> stubbedValues = ((List<?>) result).stream().map(r -> stubDMNResult(r, stubbingWrapper)).collect(Collectors.toList()); return stubbedValues; } else if (result instanceof Set<?>) { Set<?> stubbedValues = ((Set<?>) result).stream().map(r -> stubDMNResult(r, stubbingWrapper)).collect(Collectors.toSet()); return stubbedValues; } else if (result instanceof ComparablePeriod) { return ((ComparablePeriod) result).asPeriod(); } else if (result != null && result.getClass().getPackage().getName().startsWith("org.kie.dmn")) { return stubbingWrapper.apply(result); } return result; } private  MarshallingStubUtils(); static Object stubDMNResult(Object result, Function<Object, Object> stubbingWrapper);  }
@Test public void testComparablePeriod() { final DMNRuntime runtime = createRuntime("comparablePeriod.dmn", this.getClass()); final DMNModel dmnModel = runtime.getModel("https: assertThat(dmnModel, notNullValue()); final DMNContext context = runtime.newContext(); final DMNResult evaluateAll = evaluateModel(runtime, dmnModel, context); LOG.debug("{}", evaluateAll); assertThat(DMNRuntimeUtil.formatMessages(evaluateAll.getMessages()), evaluateAll.hasErrors(), is(false)); assertThat(evaluateAll.getDecisionResultByName("Decision-1").getResult(), is(ComparablePeriod.parse("P3Y"))); final Object serialized = MarshallingStubUtils.stubDMNResult(evaluateAll.getContext().getAll(), Object::toString); LOG.debug("{}", serialized); assertThat(serialized, instanceOf(Map.class)); @SuppressWarnings("unchecked") Map<String, Object> asMap = (Map<String, Object>) serialized; assertThat(asMap.get("BKM"), instanceOf(String.class)); assertThat(asMap.get("Decision-1"), instanceOf(java.time.Period.class)); assertThat(asMap.get("Decision-1"), is(java.time.Period.parse("P3Y"))); }