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