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 * 017 * @param field the field to match against. 018 * @param value the value to match against. 019 */ 020 public MetadataFieldFilter(String field, String value) { 021 022 this.field = field; 023 this.value = JsonValue.valueOf(value); 024 } 025 026 /** 027 * Create a filter for matching against a metadata field defined in JSON. 028 * 029 * @param jsonObj the JSON object to construct the filter from. 030 */ 031 public MetadataFieldFilter(JsonObject jsonObj) { 032 this.field = jsonObj.get("field").asString(); 033 034 JsonValue value = jsonObj.get("value"); 035 this.value = value; 036 } 037 038 /** 039 * Get the JSON representation of the metadata field filter. 040 * 041 * @return the JSON object representing the filter. 042 */ 043 public JsonObject getJsonObject() { 044 045 JsonObject obj = new JsonObject(); 046 obj.add("field", this.field); 047 048 obj.add("value", this.value); 049 050 return obj; 051 } 052}