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