001package Torello.Java.JSON; 002 003import javax.json.*; 004import static javax.json.JsonValue.ValueType.*; 005 006/** 007 * Used to indicate that a specific {@link JsonString} within a {@link JsonObject} or 008 * {@link JsonArray} was not properly parsed into a target <B STYLE='color: red'>Java-Type</B>. 009 * 010 * <EMBED CLASS=globalDefs DATA-STRUCT=JsonObject DATA-TYPE=Object DATA-TYPE_ABBREV=Obj> 011 * <EMBED CLASS='external-html' DATA-FILE-ID=JE_FIELD_OBJ> 012 * <EMBED CLASS='external-html' DATA-FILE-ID=JE_MSG> 013 * <EMBED CLASS='external-html' DATA-FILE-ID=JE_MSG_JSPOEX> 014 */ 015@Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="JE_SP_UL") 016@Torello.JavaDoc.CSSLinks(FileNames="JSONExceptions.css") 017public class JsonStrParseObjException extends JsonBindingObjException 018{ 019 /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUIDEX> */ 020 public static final long serialVersionUID = 1; 021 022 /** 023 * <EMBED CLASS='external-html' DATA-FILE-ID=EXPF> 024 * 025 * <BR /><BR />The {@code String} that has caused the exception. 026 */ 027 public final String s; 028 029 // This *SHOULD NOT* be necessary, but there is nothing worse than throwing another exception 030 // when building an exception. Just in case... 031 private static String CONVERT(JsonValue v) 032 { 033 return (v.getValueType() != JsonValue.ValueType.STRING) 034 ? null 035 : ((JsonString) v).getString(); 036 } 037 038 /** 039 * Constructs a {@code JsonStrParseObjException} with no specified cause, 040 * and the user-provided convenience-field values. 041 * 042 * @param cause The exception thrown by the user-provided {@code 'parser'} 043 * @param errorSourceJsonObject <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_ESJO> 044 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_PN> 045 * @param valueRetrieved <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_VR> 046 * @param methodReturnJavaType <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_MRJT> 047 */ 048 public JsonStrParseObjException( 049 Throwable cause, 050 JsonObject errorSourceJsonObject, 051 String propertyName, 052 JsonValue valueRetrieved, 053 Class<?> methodReturnJavaType 054 ) 055 { 056 super( 057 cause, errorSourceJsonObject, propertyName, STRING, valueRetrieved, 058 methodReturnJavaType, 059 "The User-Provided Parser threw an Exception while attempting to parse / transform " + 060 "a Json-String" 061 ); 062 063 this.s = CONVERT(valueRetrieved); 064 } 065 066 /** 067 * Constructs a {@code JsonStrParseObjException} with the specified detail message, cause, 068 * and user-provided convenience-field values. 069 * 070 * @param message the detail message. 071 * @param cause The exception thrown by the user-provided {@code 'parser'} 072 * @param errorSourceJsonObject <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_ESJO> 073 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_PN> 074 * @param valueRetrieved <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_VR> 075 * @param methodReturnJavaType <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_MRJT> 076 */ 077 public JsonStrParseObjException( 078 String message, 079 Throwable cause, 080 JsonObject errorSourceJsonObject, 081 String propertyName, 082 JsonValue valueRetrieved, 083 Class<?> methodReturnJavaType 084 ) 085 { 086 super( 087 message, cause, errorSourceJsonObject, propertyName, STRING, valueRetrieved, 088 methodReturnJavaType 089 ); 090 091 this.s = CONVERT(valueRetrieved); 092 } 093}