Abderrahmen
Abderrahmen

Reputation: 11

Rest WS partial JSON response

I have tried many posts found on the net before writing this question.

I'd like to have partial JSON response in my REST webservice. Frist, I've tried to return a JSONArray but I got

"No converter found for return value of type: class org.json.JSONArray"

Then I tried to return a list of JSONObject, I get

"com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0])"

When I set SerializationFeature.FAIL_ON_EMPTY_BEANS to false in my application.properties, I get a list of empty JSONObjects like : {}

I share my code in GitHub with you : https://github.com/AbderrahmenISSA/StockManagement/blob/master/src/main/java/com/stockmgt/controllers/v3/ProductControllerV3.java

Upvotes: 1

Views: 260

Answers (1)

Amara Bargougui
Amara Bargougui

Reputation: 11

in your DTO set attributes that you do not like to retrieve to null. (do it with a simple algorithm)

then configure your serilizer to not include null fields in json response. (sometimes it's the default behavior)

Upvotes: 1

Related Questions