001package com.box.sdk;
002
003/** A class representing exceptions caused from deserializing errors. */
004public class BoxDeserializationException extends RuntimeException {
005  static final long serialVersionUID = 4266400750306343595L;
006  private final String fieldName;
007  private final String fieldValue;
008
009  /**
010   * Initializes the BoxDeserializationException class.
011   *
012   * @param member the key of the json member the deserialization occurred on.
013   * @param value the value of the json member the deserialization occurred on.
014   * @param e the throwable cause for the exception.
015   */
016  public BoxDeserializationException(String member, String value, Exception e) {
017    super(constructExceptionMessage(member, value), e);
018    this.fieldName = member;
019    this.fieldValue = value;
020  }
021
022  /**
023   * Private helper function to construct the exception message for the deserialization error.
024   *
025   * @param member the field member to include in the exception message.
026   * @param value the field value to include in the exception message.
027   * @return the constructed exception message.
028   */
029  private static String constructExceptionMessage(String member, String value) {
030    return "Deserialization failed on: [ "
031        + "\"field name\": "
032        + member
033        + " | "
034        + "\"field value\": "
035        + value
036        + " ]";
037  }
038
039  /**
040   * Retrieves the field name of the deserialization error.
041   *
042   * @return field name the error occurred on.
043   */
044  public String getFieldName() {
045    return this.fieldName;
046  }
047
048  /**
049   * Retrieves the field value of the deserialization error.
050   *
051   * @return field value the error occurred on.
052   */
053  public String getFieldValue() {
054    return this.fieldValue;
055  }
056}