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 * 038 * @return field name the error occurred on. 039 */ 040 public String getFieldName() { 041 return this.fieldName; 042 } 043 044 /** 045 * Retrieves the field value of the deserialization error. 046 * 047 * @return field value the error occurred on. 048 */ 049 public String getFieldValue() { 050 return this.fieldValue; 051 } 052}