public void toJSON(PredicateQuery query, Writer writer) throws IOException {
        try (JsonGenerator g = factory.createGenerator(writer)) {
            g.writeStartObject();

            // Write features
            g.writeArrayFieldStart("features");
            for (PredicateQuery.Feature feature : query.getFeatures()) {
                writeFeature(feature.key, feature.value, feature.subqueryBitmap, g, JsonGenerator::writeStringField);
            }
            g.writeEndArray();

            // Write rangeFeatures
            g.writeArrayFieldStart("rangeFeatures");
            for (PredicateQuery.RangeFeature rangeFeature : query.getRangeFeatures()) {
                writeFeature(rangeFeature.key, rangeFeature.value, rangeFeature.subqueryBitmap, g,
                        JsonGenerator::writeNumberField);
            }
            g.writeEndArray();

            g.writeEndObject();
        }
    }
Converts {@link PredicateQuery} to and from JSON

Example:
 {
     features: [
         {"k": "key-name", "v":"value", "s":"0xDEADBEEFDEADBEEF"}
     ],
     rangeFeatures: [
         {"k": "key-name", "v":42, "s":"0xDEADBEEFDEADBEEF"}
     ]
 }

@author bjorncs
predicate-search/src/main/java/com/yahoo/search/predicate/serialization/PredicateQuerySerializer.java