001package Torello.Java.Additional;
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")
016public class JsonStrParseArrException extends JsonBindingArrException
017{
018    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUIDEX>  */
019    public static final long serialVersionUID = 1;
020
021    /**
022     * <EMBED CLASS='external-html' DATA-FILE-ID=EXPF>
023     * 
024     * <BR /><BR />The {@code String} that couldn't be properly parsed, and has caused this
025     * exception throw.
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     * Constructs a {@code JsonStrParseArrException} with no specified detail messsage,
039     * and the user-provided convenience-field values.
040     * 
041     * @param cause The exception thrown by the user-provided {@code 'parser'}
042     * @param errorSourceJsonArray  <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_ESJA>
043     * @param index                 <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_I>
044     * @param valueRetrieved        <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_VR>
045     * @param methodReturnJavaType  <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_MRJT>
046     */
047    public JsonStrParseArrException(
048            Throwable           cause,
049            JsonArray           errorSourceJsonArray,
050            int                 index,
051            JsonValue           valueRetrieved,
052            Class<?>            methodReturnJavaType
053        )
054    {
055        super(
056            cause, errorSourceJsonArray, index, STRING, valueRetrieved,
057            methodReturnJavaType,
058            "The User-Provided Parser threw an Exception while attempting to parse / transform " +
059            "a Json-String"
060        );
061
062        this.s = CONVERT(valueRetrieved);
063    }
064
065    /**
066     * Constructs a {@code JsonStrParseArrException} with the specified detail message, and
067     * user-provided convenience-field values.
068     * 
069     * @param message the detail message.
070     * @param cause The exception thrown by the user-provided {@code 'parser'}
071     * @param errorSourceJsonArray  <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_ESJA>
072     * @param index                 <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_I>
073     * @param valueRetrieved        <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_VR>
074     * @param methodReturnJavaType  <EMBED CLASS='external-html' DATA-FILE-ID=JBEX_MRJT>
075     */
076    public JsonStrParseArrException(
077            String              message,
078            Throwable           cause,
079            JsonArray           errorSourceJsonArray,
080            int                 index,
081            JsonValue           valueRetrieved,
082            Class<?>            methodReturnJavaType
083        )
084    {
085        super(
086            message, cause, errorSourceJsonArray, index, STRING, valueRetrieved,
087            methodReturnJavaType
088        );
089
090        this.s = CONVERT(valueRetrieved);
091    }
092}