Stream a List<Object> to S3 with JSON format

Viewed 41

I have big List of objects which I have to put as a single JSON file in a S3 bucket.

I can't convert the list into a byte[], because it throws

java.lang.OutOfMemoryError: Java heap space

byte[] body = objectMapper.writeValueAsBytes(myList)

I use the AsyncRequestBody

s3AsyncClient.putObject(
    PutObjectRequest.builder()
        .bucket("mybucket")
        .key("test.json")
        .contentLength((long) body.length)
        .build(),
    // AsyncRequestBody.fromByteBuffer(ByteBuffer.wrap(baos.toByteArray())))
    AsyncRequestBody.fromBytes(body)
)

How do I do it?

0 Answers
Related