001package com.nimbusds.oauth2.sdk.util;
002
003
004import net.minidev.json.JSONArray;
005
006import com.nimbusds.oauth2.sdk.ParseException;
007
008
009/**
010 * JSON array helper methods for parsing and typed retrieval of values.
011 */
012public class JSONArrayUtils {
013
014
015        /**
016         * Parses a JSON array.
017         *
018         * <p>Specific JSON to Java entity mapping (as per JSON Simple):
019         *
020         * <ul>
021         *     <li>JSON numbers mapped to {@code java.lang.Number}.
022         *     <li>JSON integer numbers mapped to {@code long}.
023         *     <li>JSON fraction numbers mapped to {@code double}.
024         * </ul>
025         *
026         * @param s The JSON array string to parse. Must not be {@code null}.
027         *
028         * @return The JSON array.
029         *
030         * @throws ParseException If the string cannot be parsed to a JSON
031         *                        array.
032         */
033        public static JSONArray parse(final String s)
034                throws ParseException {
035
036                Object o = JSONUtils.parseJSON(s);
037
038                if (o instanceof JSONArray)
039                        return (JSONArray)o;
040                else
041                        throw new ParseException("The JSON entity is not an array");
042        }
043}