{"record":{"id":"5437a32f03c88630","repo":"quarkusio/quarkus","slug":"cannot-create-jsonarray","errorCode":null,"errorMessage":"Cannot create JsonArray","messagePattern":"Cannot create JsonArray","errorType":"http","errorClass":"NoContentException","httpStatus":204,"severity":"error","filePath":"extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/vertx/JsonArrayReader.java","lineNumber":37,"sourceCode":"\n/**\n * A body reader that allows to get a Vert.x {@link JsonArray} as JAX-RS request content.\n */\n@Provider\n@Produces(MediaType.APPLICATION_JSON)\npublic class JsonArrayReader implements MessageBodyReader<JsonArray> {\n\n    @Override\n    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {\n        return type == JsonArray.class;\n    }\n\n    @Override\n    public JsonArray readFrom(Class<JsonArray> type, Type genericType, Annotation[] annotations, MediaType mediaType,\n            MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {\n        byte[] bytes = getBytes(entityStream);\n        if (bytes.length == 0) {\n            throw new NoContentException(\"Cannot create JsonArray\");\n        }\n        return new JsonArray(Buffer.buffer(bytes));\n    }\n\n    private static byte[] getBytes(InputStream entityStream) throws IOException {\n        ByteArrayOutputStream baos = new ByteArrayOutputStream();\n        byte[] buffer = new byte[4096];\n        int len;\n        while ((len = entityStream.read(buffer)) != -1) {\n            baos.write(buffer, 0, len);\n        }\n        return baos.toByteArray();\n    }\n}\n","sourceCodeStart":19,"sourceCodeEnd":52,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/vertx/JsonArrayReader.java#L19-L52","documentation":"JsonArrayReader is a JAX-RS MessageBodyReader for io.vertx.core.json.JsonArray. It reads the entity into bytes and throws NoContentException(\"Cannot create JsonArray\") when the request body is empty (0 bytes), since an empty payload cannot be parsed into a JsonArray.","triggerScenarios":"A JAX-RS resource method consumes a JsonArray body (@Consumes(APPLICATION_JSON)) but the client sends no body (Content-Length: 0 or empty chunked body), triggering readFrom with an empty entity stream.","commonSituations":"HTTP clients sending POST/PUT without a body, wrong Content-Type causing the body to be dropped, gateways/tests stripping payloads, clients intending to send [] but sending nothing due to a serialization bug.","solutions":["Make the resource method accept no-body callers explicitly (read String/InputStream yourself and treat empty as an empty array or 400).","Fix the client to always send a valid JSON body, e.g. [] for an empty array, and set Content-Type: application/json.","Return a clearer client error: add an exception mapper for NoContentException returning 400 with a helpful message."],"exampleFix":"// before\n@POST\npublic Response add(JsonArray items) { ... } // NoContentException on empty body\n\n// after\n@POST\npublic Response add(String body) {\n    if (body == null || body.isBlank()) {\n        return Response.status(400).entity(\"body required\").build();\n    }\n    JsonArray items = new JsonArray(body);\n    ...\n}","handlingStrategy":"validation","validationCode":"byte[] bytes = body == null ? new byte[0] : body.getBytes(StandardCharsets.UTF_8);\nif (bytes.length == 0) {\n    throw new WebApplicationException(\"JsonArray body required\", 400);\n}","typeGuard":"boolean hasJsonArrayBody(jakarta.ws.rs.core.HttpHeaders headers, InputStream in) throws IOException {\n    return headers.getMediaType() != null\n        && headers.getMediaType().isCompatible(jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE)\n        && in.available() > 0;\n}","tryCatchPattern":"try {\n    items = new JsonArray(entityStream.readAllBytes());\n} catch (jakarta.ws.rs.NoContentException e) {\n    items = new JsonArray(); // or abort with 400\n}","preventionTips":["Always send a JSON body (minimally []) with Content-Type: application/json.","Verify client serialization isn't dropping empty payloads.","Add tests for empty-body requests against endpoints consuming JsonArray.","Map NoContentException to a 400 with a descriptive message."],"tags":["json","jaxrs","empty-body","vertx"],"backgroundTag":"empty-request-body","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}