private static Optional<Path> getPathUsingDocumentContext(MongoResolutionContext context, String fieldName) { PathPropertySetAdapter adapter = MongoDocumentContext.isDocumentContext(context) .map(dc -> PathPropertySetAdapter.create(dc.getPropertySet())).orElse(null); if (adapter != null) { Optional<Path> path = adapter.getProperty(fieldName).flatMap(p -> adapter.getPath(p)).map(p -> (Path) p); if (path.isPresent()) { return path; } // check data path return adapter.propertyPaths() .filter(pp -> fieldName.equals(pp.getPath().relativeName(p -> p.getDataPath().orElse(p.getName())))) .map(pp -> (Path) pp.getPath()).findFirst(); } return Optional.empty(); }
final PathPropertySetAdapter adapter = PathPropertySetAdapter.create(propertySet); for (Property property : propertySet) { Optional<Path> propertyPath = adapter.getPath(property); propertyPath.ifPresent(path -> { Optional<?> value = deserializePath(context, node, ((Property<?>) property).getConfiguration(),
public void pathPropertySetAdapter1() { // tag::ppsa1[] final StringProperty STR = StringProperty.create("str"); final NumericProperty<Integer> ITG = NumericProperty.integerType("itg"); final PropertySet<?> SET = PropertySet.of(STR, ITG); final Path<String> PATH = Path.of("str", String.class); PathPropertySetAdapter adapter = PathPropertySetAdapter.create(SET); // <1> boolean contains = adapter.contains(PATH); // <2> Optional<Property<String>> property = adapter.getProperty(PATH); // <3> Optional<Path<String>> path = adapter.getPath(STR); // <4> Stream<Path<?>> paths = adapter.paths(); // <5> // end::ppsa1[] // tag::ppsa2[] PathPropertySetAdapter pathPropertySetAdapter = PathPropertySetAdapter.builder(SET) // <1> .pathConverter(new MyPathConverter()) // <2> .pathMatcher(new MyPathMatcher()) // <3> .build(); // end::ppsa2[] }