Spring application returning empty JSON
As stated on this page and adapted to your use case:
And the answer is Yes.
Flux<Chapter>
represents a stream ofChapters
. But, by default, it will produce a JSON array because If a stream of individual JSON objects is sent to the browser then It will not be a valid JSON document as a whole. A browser client has no way to consume a stream other than using Server-Sent-Events or WebSocket.However, Non-browser clients can request a stream of JSON by setting the Accept header to
application/stream+json
, and the response will be a stream of JSON similar to Server-Sent-Events but without extra formatting :
So in your case you request the result in your Browser. If you would add the appropriate accept header
to application/stream+json
you will get the wanted output.
Could be lombok dependancy issue. Try writing setter and getter methods instead of lombok.
I've had the very same issue, and for me I had to ensure my IDE had Lombok annotation processing enabled (I'm using IntelliJ Ultimate). When enabling this and restarting my app, I started seeing data as expected and not empty JSON arrays.