001package com.box.sdk;
002
003import com.eclipsesource.json.JsonObject;
004import com.eclipsesource.json.JsonValue;
005
006/**
007 * Filter for matching against a metadata field.
008 */
009public class MetadataFieldFilter {
010
011    private String field;
012    private JsonValue value;
013
014    /**
015     * Create a filter for matching against a string metadata field.
016     * @param field the field to match against.
017     * @param value the value to match against.
018     */
019    public MetadataFieldFilter(String field, String value) {
020
021        this.field = field;
022        this.value = JsonValue.valueOf(value);
023    }
024
025    /**
026     * Create a filter for matching against a metadata field defined in JSON.
027     * @param jsonObj the JSON object to construct the filter from.
028     */
029    public MetadataFieldFilter(JsonObject jsonObj) {
030        this.field = jsonObj.get("field").asString();
031
032        JsonValue value = jsonObj.get("value");
033        this.value = value;
034    }
035
036    /**
037     * Get the JSON representation of the metadata field filter.
038     * @return the JSON object representing the filter.
039     */
040    public JsonObject getJsonObject() {
041
042        JsonObject obj = new JsonObject();
043        obj.add("field", this.field);
044
045        obj.add("value", this.value);
046
047        return obj;
048    }
049}