Serializer not found for class org.json.JSONObject and no properties found to create BeanSerializer

with JSON from web service, Json Array as response

[3] 0: { id: 2 name: "a561137" password: "test" firstName: "abhishek" lastName: "ringsia" organization: "bbb" }- 1: { id: 3 name: "a561023" password: "hello" firstName: "hello" lastName: "hello" organization: "hello" }- 2: { id: 4 name: "a541234" password: "hello" firstName: "hello" lastName: "hello" organization: "hello" } 

After receiving a response in JsonArray Getting error reading Json Object Json Array:

  List<User> list = new ArrayList<User>(); JSONArray jsonArr = new JSONArray(response); for (int i = 0; i < jsonArr.length(); i++) { JSONObject jsonObj = jsonArr.getJSONObject(i); ObjectMapper mapper = new ObjectMapper(); User usr= mapper.convertValue(jsonObj, User.class); list.add(usr); } 

A serial analyzer was not found for the class org.json.JSONObject and no properties were found to create the BeanSerializer (to avoid an exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS)

+8
java json spring rest serialization
source share
1 answer

Take it first as a Json Array, then, while reading its Object, you need to use Object Mapper.readValue, because Json Object is Still in String.

 List<User> list = new ArrayList<User>(); JSONArray jsonArr = new JSONArray(response); for (int i = 0; i < jsonArr.length(); i++) { JSONObject jsonObj = jsonArr.getJSONObject(i); ObjectMapper mapper = new ObjectMapper(); User usr = mapper.readValue(jsonObj.toString(), User.class); list.add(usr); } 
+2
source share

All Articles