use of com.robo4j.util.Utf8Constant.UTF8_SQUARE_BRACKET_LEFT in project robo4j by Robo4J.
the class ReflectUtils method processCollectionToJson.
@SuppressWarnings("unchecked")
private static String processCollectionToJson(ClassGetSetDTO getterDTO, TypeMapper typeMapper, Object obj) {
JsonElementStringBuilder result = JsonElementStringBuilder.Builder();
JsonTypeAdapter jsonTypeAdapter = getAdapterByClazz(getterDTO.getValueClass(), typeMapper);
switch(getterDTO.getCollection()) {
case ARRAY:
Object[] arrayObjects = (Object[]) obj;
String arrayValue = Stream.of(arrayObjects).map(element -> jsonTypeAdapter.adapt(element)).collect(Collectors.joining(UTF8_COMMA));
// formatter:off
result.add(UTF8_SQUARE_BRACKET_LEFT).add(arrayValue).add(UTF8_SQUARE_BRACKET_RIGHT);
break;
case LIST:
List<Object> objects = (List<Object>) obj;
String listValue = objects.stream().map(element -> jsonTypeAdapter.adapt(element)).collect(Collectors.joining(UTF8_COMMA));
// formatter:off
result.add(UTF8_SQUARE_BRACKET_LEFT).add(listValue).add(UTF8_SQUARE_BRACKET_RIGHT);
// formatter:on
break;
case MAP:
Map<Object, Object> objectMap = (Map<Object, Object>) obj;
result.add(UTF8_CURLY_BRACKET_LEFT).add(objectMap.entrySet().stream().map(entry -> JsonElementStringBuilder.Builder().addQuotationWithDelimiter(UTF8_COLON, entry.getKey()).add(jsonTypeAdapter.adapt(entry.getValue())).build()).collect(Collectors.joining(UTF8_COMMA))).add(UTF8_CURLY_BRACKET_RIGHT);
break;
}
return result.build();
}
Aggregations