Class ProcessMultiDimJsonArray

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method
      protected static <BASIC_TYPE,
           ​STREAM_TYPE,
           ​RETURN_ARR_TYPE>
      RETURN_ARR_TYPE
      jsonArrayToJava​(JsonArray ja, SettingsRec<BASIC_TYPE,​STREAM_TYPE> rec, Class<RETURN_ARR_TYPE> retArrClass)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • jsonArrayToJava

          🗕  🗗  🗖
        protected static <BASIC_TYPE,​STREAM_TYPE,​RETURN_ARR_TYPE> RETURN_ARR_TYPE jsonArrayToJava​
                    (JsonArray ja,
                     SettingsRec<BASIC_TYPE,​STREAM_TYPE> rec,
                     java.lang.Class<RETURN_ARR_TYPE> retArrClass)
        
        Code:
        Exact Method Body:
         // If this is requesting a one-dimensional array, get it using the 1D-Generator,
         // and simply return that array.  This requires a cast because there is no way to prove
         // to the Java-Compiler that <T> is equal to any return-value at all.
         //
         // Remember that this is only guaranteed (it works!) because the helper methods are all
         // protected or private, and it has been guaranteed through rigorous testing, and
         // preventing the user from playing with it!
        
         if (StringParse.countCharacters(retArrClass.getSimpleName(), '[') == 1)
             return (RETURN_ARR_TYPE) rec.array1DGenerator.apply(ja);
        
        
         // Otherwise, this is not a single-dimension (1D) array.  Instead, the JsonArray needs
         // to be iterated, and this method called, recursively, on each of the sub-arrays.
         //
         // NOTE: 'compClass' will also be an array, but with one fewer dimensions
        
         final Class<?>          compClass   = retArrClass.getComponentType();
         final int               SIZE        = ja.size();
         final RETURN_ARR_TYPE   retArr      = (RETURN_ARR_TYPE) Array.newInstance(compClass, SIZE);
        
         JsonValue jv = null;
        
         for (int i=0; i < SIZE; i++)
        
             switch ((jv = ja.get(i)).getValueType())
             {
                 // javax.json.JsonValue.ValueType.NULL
                 case NULL: Array.set(retArr, i, null); break;
        
                 // javax.json.JsonValue.ValueType.ARRAY (JsonArray)
                 case ARRAY:
        
                     Array.set(
                         retArr,
                         i,
                         JSON_ARRAY_DIMN.jsonArrayToJava((JsonArray) jv, rec, compClass)
                     );
        
                     break;
        
                 // javax.json.JsonValue.ValueType.TRUE, FALSE, NUMBER, STRING, OBJECT
                 default:
        
                     if (rec.IN_NSAT)        Array.set(retArr, i, null);
                     else if (rec.S_NSAT)    continue;
                     else throw new JsonTypeArrException(ja, i, ARRAY, jv, retArrClass);
             }
        
         return retArr;