Code example for JsonArray

Methods: getsize

0
    throws JsonParseException 
  { 
    Operation operation = null;
    if( json instanceof JsonArray ) {
      JsonArray opArray = ( JsonArray )json;
      String action = opArray.get( 0 ).getAsString();
      operation = createOperationFromJsonArray( action, opArray, context );
    } 
    return operation;
  } 
 
  private Operation createOperationFromJsonArray( String action,
                                                  JsonArray opArray,
                                                  JsonDeserializationContext context )
  { 
    Operation result = null;
    if( CreateOperation.ACTION.equals( action ) ) {
      result = createCreateOperation( opArray, context );
    } else if( SetOperation.ACTION.equals( action ) ) {
      result = createSetOperation( opArray, context );
    } else if( ListenOperation.ACTION.equals( action ) ) {
      result = createListenOperation( opArray, context );
    } else if( CallOperation.ACTION.equals( action ) ) {
      result = createCallOperation( opArray, context );
    } else if( DestroyOperation.ACTION.equals( action ) ) {
      result = new DestroyOperation();
    } else { 
      throw new JsonParseException( "Unknown type of operation " + opArray );
    } 
    result.setTarget( getTarget( opArray ) );
    return result;
  } 
 
  private Operation createCallOperation( JsonArray opArray, JsonDeserializationContext context ) {
    CallOperation co = new CallOperation();
    co.setMethod( opArray.get( 2 ).getAsString() );
    if( opArray.size() >= 4 ) {
      co.setProperties( ( CallProperties )context.deserialize( opArray.get( 3 ),
                                                               CallProperties.class ) ); 
    } 
    return co;
  } 
 
  private Operation createListenOperation( JsonArray opArray, JsonDeserializationContext context ) {
    ListenOperation lo = new ListenOperation();
    if( opArray.size() >= 3 ) {
      lo.setProperties( ( ListenProperties )context.deserialize( opArray.get( 2 ),
                                                                 ListenProperties.class ) ); 
    } 
    return lo;
  } 
 
  private Operation createSetOperation( JsonArray opArray, JsonDeserializationContext context ) {
    SetOperation so = new SetOperation();
    so.setProperties( ( SetProperties )context.deserialize( opArray.get( 2 ), SetProperties.class ) );
    return so;
  } 
 
  private Operation createCreateOperation( JsonArray opArray, JsonDeserializationContext context ) {
    CreateOperation co = new CreateOperation();
    co.setType( opArray.get( 2 ).getAsString() );
    if( opArray.size() >= 4 ) {
      co.setProperties( ( CreateProperties )context.deserialize( opArray.get( 3 ),
                                                                 CreateProperties.class ) ); 
    } 
    return co;
  } 
 
  private String getTarget( JsonArray opArray ) {
    String target = opArray.get( 1 ).getAsString();
    if( target == null ) {
      throw new JsonParseException( "Target of operation must not be null " + opArray );
    } 
    return target;
  } 
Experience pair programming with AI  Get Codota for Java