Java Code Examples for javax.json.JsonArray#getString()

The following examples show how to use javax.json.JsonArray#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobProcessor.java    From herd-mdl with Apache License 2.0 6 votes vote down vote up
String getStorageNames( JobDefinition od ) {
	String correlation = od.getCorrelation();
	String storageNames = "?";

	if ( !StringUtils.isEmpty( correlation ) && !correlation.equals( "null" ) ) {
		JsonReader reader = Json.createReader( new StringReader( correlation ) );
		JsonObject object = reader.readObject();
		if ( object.containsKey( "businessObject" ) ) {
			JsonObject ob = object.getJsonObject( "businessObject" );
			if ( ob.containsKey( "storageNames" ) ) {
				JsonArray a = ob.getJsonArray( "storageNames" );
				storageNames = "";
				for ( int i = 0; i < a.size(); i++ ) {
					storageNames += a.getString( i );
					if ( i != a.size() - 1 ) {
						storageNames += ",";
					}
				}
			}
		}
	}
	return storageNames;
}
 
Example 2
Source File: Group.java    From sample-acmegifts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a group based on a JSON Object
 *
 * @param group The JSON Object with group information
 */
public Group(JsonObject group) {
  if (group.containsKey(JSON_KEY_GROUP_ID)) {
    id = group.getString(JSON_KEY_GROUP_ID);
  }
  name = group.getString(JSON_KEY_GROUP_NAME);

  JsonArray jsonMembers = group.getJsonArray(JSON_KEY_MEMBERS_LIST);
  if (jsonMembers != null) {
    members = new String[jsonMembers.size()];
    for (int i = 0; i < jsonMembers.size(); i++) {
      members[i] = jsonMembers.getString(i);
    }
  } else {
    members = new String[0];
  }
}
 
Example 3
Source File: LibrariesTest.java    From appengine-plugins-core with Apache License 2.0 6 votes vote down vote up
@Test
public void testServiceRoleMapping_hasNoDuplicateRoles() {
  for (JsonObject api : apis) {
    JsonArray serviceRoles = api.getJsonArray("serviceRoles");
    if (serviceRoles != null) {
      Set<String> roles = Sets.newHashSet();
      for (int i = 0; i < serviceRoles.size(); i++) {
        String role = serviceRoles.getString(i);
        if (roles.contains(role)) {
          Assert.fail("Role: " + role + " is defined multiple times");
        }
        roles.add(role);
      }
    }
  }
}
 
Example 4
Source File: Group.java    From sample-acmegifts with Eclipse Public License 1.0 5 votes vote down vote up
public Group(String json) throws Exception {
  JsonObject jObject = stringToJsonObj(json);
  this.id = jObject.getString(JSON_KEY_GROUP_ID);
  this.name = jObject.getString(JSON_KEY_GROUP_NAME);

  JsonArray jsonMembers = jObject.getJsonArray(JSON_KEY_MEMBERS_LIST);
  if (jsonMembers != null) {
    members = new String[jsonMembers.size()];
    for (int i = 0; i < jsonMembers.size(); i++) {
      members[i] = jsonMembers.getString(i);
    }
  } else {
    members = new String[0];
  }
}
 
Example 5
Source File: JSONContentHandler.java    From jcypher with Apache License 2.0 5 votes vote down vote up
@Override
public PathInfo getPathInfo(String colKey) {
	PathInfo pathInfo = null;
	int colIdx = getColumnIndex(colKey);
	if (colIdx == -1)
		throw new RuntimeException("no result column: " + colKey);
	JsonObject dataObject = (JsonObject) this.jsonValue;
	JsonArray restArray = getRestArray(dataObject);
	JsonValue restValue = getRestValue(restArray, colIdx);
	restValue = this.handleArrayCase(restValue);
	
	if (restValue.getValueType() == ValueType.OBJECT) {
		JsonObject pathObject = (JsonObject) restValue;
		String str = pathObject.getString("start");
		long startId = Long.parseLong(str.substring(str.lastIndexOf('/') + 1));
		str = pathObject.getString("end");
		long endId = Long.parseLong(str.substring(str.lastIndexOf('/') + 1));
		JsonArray rels = pathObject.getJsonArray("relationships");
		List<Long> relIds = new ArrayList<Long>();
		int sz = rels.size();
		for (int i = 0; i < sz; i++) {
			String rel = rels.getString(i);
			long rid = Long.parseLong(rel.substring(rel.lastIndexOf('/') + 1));
			relIds.add(Long.valueOf(rid));
		}
		pathInfo = new PathInfo(startId, endId, relIds, pathObject);
	}
	return pathInfo;
}
 
Example 6
Source File: VTypeJsonMapper.java    From diirt with MIT License 5 votes vote down vote up
public List<Class<?>> getColumnTypes(String string) {
    JsonArray array = getJsonArray(string);
    List<Class<?>> types = new ArrayList<>();
    for (int i = 0; i < array.size(); i++) {
        String type = array.getString(i);
        if ("String".equals(type)) {
            types.add(String.class);
        } else if ("double".equals(type)) {
            types.add(double.class);
        } else if ("float".equals(type)) {
            types.add(float.class);
        } else if ("long".equals(type)) {
            types.add(long.class);
        } else if ("int".equals(type)) {
            types.add(int.class);
        } else if ("short".equals(type)) {
            types.add(short.class);
        } else if ("byte".equals(type)) {
            types.add(byte.class);
        } else if ("Timestamp".equals(type)) {
            types.add(Instant.class);
        } else {
            throw new IllegalArgumentException("Column type " + type + " not supported");
        }
    }
    return types;
}
 
Example 7
Source File: ApplicationBuilder.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
/** Configures the application struucture from a JSON document.
 *
 * @param root The JSON document root.
 * @throws AssemblyException if probelms in the Assemblers provided in the JSON document.
 */
protected void configureWithJson( JsonObject root )
    throws AssemblyException
{
    JsonValue optLayers = root.get( "layers" );
    if( optLayers != null && optLayers.getValueType() == JsonValue.ValueType.ARRAY )
    {
        JsonArray layers = (JsonArray) optLayers;
        for( int i = 0; i < layers.size(); i++ )
        {
            JsonObject layerObject = layers.getJsonObject( i );
            String layerName = layerObject.getString( "name" );
            LayerDeclaration layerDeclaration = withLayer( layerName );
            JsonValue optUsing = layerObject.get( "uses" );
            if( optUsing != null && optUsing.getValueType() == JsonValue.ValueType.ARRAY )
            {
                JsonArray using = (JsonArray) optUsing;
                for( int j = 0; j < using.size(); j++ )
                {
                    layerDeclaration.using( using.getString( j ) );
                }
            }
            JsonValue optModules = layerObject.get( "modules" );
            if( optModules != null && optModules.getValueType() == JsonValue.ValueType.ARRAY )
            {
                JsonArray modules = (JsonArray) optModules;
                for( int k = 0; k < modules.size(); k++ )
                {
                    JsonObject moduleObject = modules.getJsonObject( k );
                    String moduleName = moduleObject.getString( "name" );
                    ModuleDeclaration moduleDeclaration = layerDeclaration.withModule( moduleName );
                    JsonValue optAssemblers = moduleObject.get( "assemblers" );
                    if( optAssemblers != null && optAssemblers.getValueType() == JsonValue.ValueType.ARRAY )
                    {
                        JsonArray assemblers = (JsonArray) optAssemblers;
                        for( int m = 0; m < assemblers.size(); m++ )
                        {
                            String string = assemblers.getString( m );
                            moduleDeclaration.withAssembler( string );
                        }
                    }
                }
            }
        }
    }
}