Search in sources :

Example 1 with ResponseAttributeListDTO

use of com.robo4j.socket.http.dto.ResponseAttributeListDTO in project robo4j by Robo4J.

the class JsonUtil method toJsonArrayServer.

public static <T> String toJsonArrayServer(List<T> list) {
    return JsonElementStringBuilder.Builder().add(Utf8Constant.UTF8_SQUARE_BRACKET_LEFT).add(list.stream().map(e -> {
        if (e instanceof ResponseAttributeDTO) {
            ResponseAttributeDTO ra = (ResponseAttributeDTO) e;
            switch(ra.getType()) {
                case "java.util.ArrayList":
                    List<HttpPathMethodDTO> tmpList = JsonUtil.readPathConfig(HttpPathMethodDTO.class, ra.getValue());
                    ResponseAttributeListDTO tmpAttr = new ResponseAttributeListDTO();
                    tmpAttr.setId(ra.getId());
                    tmpAttr.setType(ra.getType());
                    tmpAttr.setValue(tmpList);
                    return ReflectUtils.createJson(tmpAttr);
                default:
                    return ReflectUtils.createJson(e);
            }
        } else {
            return ReflectUtils.createJson(e);
        }
    }).collect(Collectors.joining(Utf8Constant.UTF8_COMMA))).add(Utf8Constant.UTF8_SQUARE_BRACKET_RIGHT).build();
}
Also used : ResponseAttributeDTO(com.robo4j.socket.http.dto.ResponseAttributeDTO) ResponseAttributeListDTO(com.robo4j.socket.http.dto.ResponseAttributeListDTO) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO)

Example 2 with ResponseAttributeListDTO

use of com.robo4j.socket.http.dto.ResponseAttributeListDTO in project robo4j by Robo4J.

the class ReflectUtilTests method serverAttributesResponse.

@Test
void serverAttributesResponse() {
    ResponseAttributeListDTO tmpAttr = new ResponseAttributeListDTO();
    tmpAttr.setType("Type");
    tmpAttr.setId("ID");
    // String roboUnit, HttpMethod method, List<String> callbacks
    tmpAttr.addValue(new HttpPathMethodDTO("testUnit", HttpMethod.GET, Collections.singletonList("test")));
    String result = ReflectUtils.createJson(tmpAttr);
    System.out.println("result:" + result);
}
Also used : ResponseAttributeListDTO(com.robo4j.socket.http.dto.ResponseAttributeListDTO) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Aggregations

HttpPathMethodDTO (com.robo4j.socket.http.dto.HttpPathMethodDTO)2 ResponseAttributeListDTO (com.robo4j.socket.http.dto.ResponseAttributeListDTO)2 ResponseAttributeDTO (com.robo4j.socket.http.dto.ResponseAttributeDTO)1 Test (org.junit.jupiter.api.Test)1