001package com.box.sdk; 002 003import com.eclipsesource.json.Json; 004import com.eclipsesource.json.JsonObject; 005import com.eclipsesource.json.JsonValue; 006 007/** Filter for matching against a metadata field. */ 008public class MetadataFieldFilter { 009 010 private final String field; 011 private final JsonValue value; 012 013 /** 014 * Create a filter for matching against a string metadata field. 015 * 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 = Json.value(value); 023 } 024 025 /** 026 * Create a filter for matching against a metadata field defined in JSON. 027 * 028 * @param jsonObj the JSON object to construct the filter from. 029 */ 030 public MetadataFieldFilter(JsonObject jsonObj) { 031 this.field = jsonObj.get("field").asString(); 032 this.value = jsonObj.get("value"); 033 } 034 035 /** 036 * Get the JSON representation of the metadata field filter. 037 * 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}