use of com.alipay.hessian.generic.model.GenericMap in project incubator-shenyu by apache.
the class SofaParamResolveServiceImpl method convertToParameterValue.
/**
* convert to parameter value.
*
* @param value value support [json object string, json array string,string]
* @param parameterType parameter type support [javaPackage.ClassName#GenericType1#GenericType2], split is ,
* @return GenericObject, GenericMap, List, string, array...
* @see com.alipay.hessian.generic.model
*/
@SuppressWarnings("all")
private Object convertToParameterValue(final Object value, final String[] parameterType) {
if (isSingleType(parameterType)) {
return value;
}
if (value instanceof JsonObject && parameterType[0].contains("Map")) {
final Map<String, Object> mapValue = GsonUtils.getInstance().convertToMap(value.toString());
if (parameterType.length == 1) {
// no generic info
return mapValue;
}
assert parameterType.length == 3;
// generic map
final GenericMap genericMap = new GenericMap(parameterType[2]);
mapValue.replaceAll((k, v) -> convertToGenericObject(parameterType[2], mapValue.get(k)));
genericMap.setMap(mapValue);
return genericMap;
}
if (value instanceof JsonObject) {
return convertToGenericObject(parameterType[0], value);
}
if (value instanceof JsonArray) {
if (parameterType.length == 1) {
// no generic info
return GsonUtils.getInstance().fromList(value.toString(), Object.class);
}
// generic collection
final GenericCollection genericCollection = new GenericCollection(parameterType[1]);
genericCollection.setCollection(convertToGenericObjects(parameterType[1], (Iterable<Object>) value));
return genericCollection;
}
return value;
}
Aggregations