use of org.ballerinalang.jvm.values.MapValue in project product-microgateway by wso2.
the class MGWJWTGeneratorInvoker method convertMapValueToMap.
/**
* Convert MapValue to Map.
*/
public static Map<String, Object> convertMapValueToMap(MapValue mapValue) {
Map<String, Object> map = new HashMap<>();
for (Object key : mapValue.getKeys()) {
Object valueObject = mapValue.get(key.toString());
if (valueObject != null && valueObject instanceof MapValue) {
MapValue subMapValue = mapValue.getMapValue(key.toString());
Map<String, Object> subMap = convertMapValueToMap(subMapValue);
map.put(key.toString(), subMap);
} else if (valueObject != null && valueObject instanceof ArrayValue) {
ArrayValue arrayValue = mapValue.getArrayValue(key.toString());
map.put(key.toString(), convertArrayValueToArray(arrayValue));
} else {
map.put(key.toString(), valueObject);
}
}
return map;
}
use of org.ballerinalang.jvm.values.MapValue in project product-microgateway by wso2.
the class Request method getQueryParamValue.
/**
* Gets the query param value associated with the given key.
*
* @param key Represents the query param key.
* @return Returns the query param value associated with the given key as a string. If multiple param values are
* present, then the first value is returned. Null is returned if no key is found.
*/
public String getQueryParamValue(String key) {
BMap mapValue = getNativeQueryParams();
BArray arrayValue = ((MapValue) mapValue).getArrayValue(key);
if (arrayValue != null) {
return arrayValue.get(0).toString();
}
return null;
}
use of org.ballerinalang.jvm.values.MapValue in project product-microgateway by wso2.
the class Request method getQueryParamValues.
/**
* Gets all the query param values associated with the given key.
*
* @param key Represents the query param key.
* @return Returns all the query param values associated with the given key as a `String[]`.
* Null is returned if no key is found.
*/
public String[] getQueryParamValues(String key) {
BMap mapValue = getNativeQueryParams();
BArray arrayValue = ((MapValue) mapValue).getArrayValue(key);
if (arrayValue != null) {
return arrayValue.getStringArray();
}
return null;
}
use of org.ballerinalang.jvm.values.MapValue in project product-microgateway by wso2.
the class MappingInvoker method convertMapValueToMap.
/**
* Convert MapValue to Map.
*/
public static Map<String, Object> convertMapValueToMap(MapValue mapValue) throws Exception {
Map<String, Object> map = new HashMap<>();
for (Object key : mapValue.getKeys()) {
Object valueObject = mapValue.get(key.toString());
if (valueObject != null && valueObject instanceof MapValue) {
MapValue subMapValue = mapValue.getMapValue(key.toString());
Map<String, Object> subMap = convertMapValueToMap(subMapValue);
map.put(key.toString(), subMap);
} else if (valueObject != null && valueObject instanceof ArrayValue) {
ArrayValue arrayValue = mapValue.getArrayValue(key.toString());
Object[] array = new Object[arrayValue.size()];
for (int i = 0; i < arrayValue.size(); i++) {
if (arrayValue.get(i) instanceof MapValue) {
array[i] = convertMapValueToMap((MapValue) arrayValue.get(i));
} else {
array[i] = arrayValue.get(i);
}
}
map.put(key.toString(), array);
} else {
map.put(key.toString(), valueObject);
}
}
return map;
}
Aggregations