private <T extends BatchProgram> List<T> validateAndGetBatchInput(FullHttpRequest request, Type type) throws BadRequestException, IOException { List<T> programs; try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) { try { programs = DECODE_GSON.fromJson(reader, type); if (programs == null) { throw new BadRequestException("Request body is invalid json, please check that it is a json array."); } } catch (JsonSyntaxException e) { throw new BadRequestException("Request body is invalid json: " + e.getMessage()); } } // validate input for (BatchProgram program : programs) { try { program.validate(); } catch (IllegalArgumentException e) { throw new BadRequestException( "Must provide valid appId, programType, and programId for each object: " + e.getMessage()); } } return programs; }
private <T extends BatchProgram> List<T> validateAndGetBatchInput(FullHttpRequest request, Type type) throws BadRequestException, IOException { List<T> programs; try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) { try { programs = DECODE_GSON.fromJson(reader, type); if (programs == null) { throw new BadRequestException("Request body is invalid json, please check that it is a json array."); } } catch (JsonSyntaxException e) { throw new BadRequestException("Request body is invalid json: " + e.getMessage()); } } // validate input for (BatchProgram program : programs) { try { program.validate(); } catch (IllegalArgumentException e) { throw new BadRequestException( "Must provide valid appId, programType, and programId for each object: " + e.getMessage()); } } return programs; }