0

I'm looking to form a QueryDSL Path where there is a Map somewhere in the object hierarchy. If I just have simple object hierarchies, I can do the following, which works:

        BooleanBuilder builder = new BooleanBuilder();
        Path path = Expressions.path(Outer.class, "root");
        path = Expressions.path(Inner.class, path, "inner");
        builder.and(Expressions.path(String.class, path, "field").eq("test"));

However, I'm a bit confused when coming to a Map. There doesn't seem to be method parameter to pass in the root path, so I'm just at a loss on what to do. Passing the Path metadata doesn't seem to work, but I really didn't expect it to. And there is also no place to pass in the property name that is the map.

        BooleanBuilder builder = new BooleanBuilder();
        Path path = Expressions.path(Outer.class, "root");
        path = Expressions.mapPath(String.class, String.class, StringPath.class, path.getMetadata()); // What would be the proper way to dive down into the map?
        builder.and(Expressions.path(String.class, path, "field").eq("test"));

Clearly I do not understand the proper use of this method, but I am unable to glean what the proper use would be.

Also of note, I'm trying to do this dynamically, so even though I could use Q-generated classes in these examples, that isn't my final goal.

So if I had an object structure of Outer.map[key].field, how could I build a Path to select field?

The closest question I found was QueryDsl web query on the key of a Map field, but that assumes directly accessing a dictionary, not having a dictionary somewhere in the path.

MVinca
  • 291
  • 2
  • 4
  • 11

0 Answers0