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=JsonArray DATA-TYPE=Array DATA-TYPE_ABBREV=Arr>
011 * <EMBED CLASS='external-html' DATA-FILE-ID=JE_FIELD_ARR>
012 * <EMBED CLASS='external-html' DATA-FILE-ID=JE_MSG>
013 * <EMBED CLASS='external-html' DATA-FILE-ID=JE_MSG_JSPAEX>
014 */
015@Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="JE_SP_UL")
016@Torello.JavaDoc.CSSLinks(FileNames="JSONExceptions.css")
017public class JsonStrParseArrException extends JsonBindingArrException
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 couldn't be properly parsed, and has caused this
026     * exception throw.
027     */
028    public final String s;
029
030    // This *SHOULD NOT* be necessary, but there is nothing worse than throwing another exception
031    // when building an exception.  Just in case...
032    private static String CONVERT(JsonValue v)
033    {
034        return (v.getValueType() != JsonValue.ValueType.STRING)
035            ? null
036            : ((JsonString) v).getString();
037    }
038    /**
039     * Constructs a {@code JsonStrParseArrException} with no specified detail messsage,
040     * and the user-provided convenience-field values.
041     * 
042     * @param cause The exception thrown by the user-provided {@code 'parser'}
043     * @param errorSourceJsonArray  <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_ESJA>
044     * @param index                 <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_I>
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 JsonStrParseArrException(
049            Throwable           cause,
050            JsonArray           errorSourceJsonArray,
051            int                 index,
052            JsonValue           valueRetrieved,
053            Class<?>            methodReturnJavaType
054        )
055    {
056        super(
057            cause, errorSourceJsonArray, index, 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 JsonStrParseArrException} with the specified detail message, and
068     * 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 errorSourceJsonArray  <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_ESJA>
073     * @param index                 <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_I>
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 JsonStrParseArrException(
078            String              message,
079            Throwable           cause,
080            JsonArray           errorSourceJsonArray,
081            int                 index,
082            JsonValue           valueRetrieved,
083            Class<?>            methodReturnJavaType
084        )
085    {
086        super(
087            message, cause, errorSourceJsonArray, index, STRING, valueRetrieved,
088            methodReturnJavaType
089        );
090
091        this.s = CONVERT(valueRetrieved);
092    }
093}