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