All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.monitorjbl.json.JsonView Maven / Gradle / Ivy

package com.monitorjbl.json;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * Allows runtime alteration of JSON responses
 */
public class JsonView {
  protected final T value;
  protected final Map, Match> matches = new HashMap<>();
  protected MatcherBehavior matcherBehavior;

  protected JsonView(T value) {
    this.value = value;
  }

  T getValue() {
    return value;
  }

  Match getMatch(Class cls) {
    return matches.get(cls);
  }

  public JsonView onClass(Class cls, Match match) {
    matches.put(cls, match);
    return this;
  }

  public JsonView withMatcherBehavior(MatcherBehavior matcherBehavior) {
    this.matcherBehavior = matcherBehavior;
    return this;
  }

  @Override
  public boolean equals(Object o) {
    if(this == o) return true;
    if(o == null || getClass() != o.getClass()) return false;
    JsonView jsonView = (JsonView) o;
    return Objects.equals(matches, jsonView.matches) &&
        matcherBehavior == jsonView.matcherBehavior;
  }

  @Override
  public int hashCode() {
    return Objects.hash(matches, matcherBehavior);
  }

  public static  JsonView with(E value) {
    return new JsonView<>(value);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy