rest-query-engine icon indicating copy to clipboard operation
rest-query-engine copied to clipboard

Querying of java.util.Map

Open bosbeles opened this issue 7 years ago • 1 comments

if(rsql != null) { QueryConversionPipeline pipeline = QueryConversionPipeline.defaultPipeline(); Condition<GeneralQueryBuilder> condition = pipeline.apply(rsql, Notification.class); Criteria criteria = condition.query(new MongoVisitor()); query.addCriteria(criteria); }

Suppose you have a class Notification.class with a field: private Map<String, Object> data; And you're querying "data.category==cat-1" where category is a key of a map. Then EntityFieldTypeResolver throws a null pointer exception. I changed its apply method as follows: @Override public Class> apply(FieldPath path, Class> root) { String[] splitField = path.asKey().split("\.", 2); Field field = getField(root, splitField[0], true); if(field == null) { return Object.class; }

    if(splitField.length == 1) {

        return normalize(field);
    } else {
        return apply(new FieldPath(splitField[1]), normalize(field));
    }
} 

But is this the right approach? Is it possible to add map inside maps etc. a more generic approach I mean.

bosbeles avatar Jul 12 '18 08:07 bosbeles

is there any idea? why we can not query for Map attributes

emreesirik avatar Sep 02 '19 13:09 emreesirik