Logo Search packages:      
Sourcecode: libjson-java version File versions

static List net::sf::json::JSONArray::toList ( JSONArray  jsonArray,
JsonConfig  jsonConfig 
) [inline, static]

Creates a List from a JSONArray.

Deprecated:
replaced by toCollection
See also:
toCollection(JSONArray,JsonConfig)

Definition at line 609 of file JSONArray.java.

References net::sf::json::JsonConfig::copy(), get(), net::sf::json::JsonConfig::getClassMap(), net::sf::json::JsonConfig::getRootClass(), net::sf::json::JsonConfig::setClassMap(), net::sf::json::JsonConfig::setRootClass(), size(), and toList().

                                                                           {
      if( jsonArray.size() == 0 ){
         return new ArrayList();
      }

      Class objectClass = jsonConfig.getRootClass();
      Map classMap = jsonConfig.getClassMap();

      List list = new ArrayList();
      int size = jsonArray.size();
      for( int i = 0; i < size; i++ ){
         Object value = jsonArray.get( i );
         if( JSONUtils.isNull( value ) ){
            list.add( null );
         }else{
            Class type = value.getClass();
            if( JSONArray.class.isAssignableFrom( type ) ){
               list.add( toList( (JSONArray) value, objectClass, classMap ) );
            }else if( String.class.isAssignableFrom( type )
                  || Boolean.class.isAssignableFrom( type ) || JSONUtils.isNumber( type )
                  || Character.class.isAssignableFrom( type )
                  || JSONFunction.class.isAssignableFrom( type ) ){
               if( objectClass != null && !objectClass.isAssignableFrom( type ) ){
                  value = JSONUtils.getMorpherRegistry()
                        .morph( objectClass, value );
               }
               list.add( value );
            }else{
               if( objectClass != null ){
                  JsonConfig jsc = jsonConfig.copy();
                  jsc.setRootClass( objectClass );
                  jsc.setClassMap( classMap );
                  list.add( JSONObject.toBean( (JSONObject) value, jsc ) );
               }else{
                  list.add( JSONObject.toBean( (JSONObject) value ) );
               }
            }
         }
      }
      return list;
   }


Generated by  Doxygen 1.6.0   Back to index