-2
{"field": {"11815": {"name": "email","value": "snow.fx@qq.com"},"11816": {"name": "storeid","value": "11"},"12116": {"name": "idcardtypeid","value": "1"},"12117": {"name": "idcardno","value": "320282199207071967"}},"birthday": "1992-7-7","name": "cccc","gender": 2,"openid": "90738","mobile": "1000"}

this is the json string, I wanna parse it to a entity class, define like:

@JsonIgnoreProperties(ignoreUnknown = true)
public class Userinfo(){String name; int gender; .... ; JSONObject field}

I used ObjectMapper to parse, code is:

Userinfo userinfo = new ObjectMapper().readValue(jsonStr ,Userinfo.class)

but it still give error message 'Unrecognized field "11216", not marked as i ignorable'.

"birthday", "name", "mobile", "openid", easy to solve. but "field" has "11815","11816","12116","12117", I can't define a variable named "11815", it's illegal in Java

2 Answers2

0

Create a class with the field names representing Key names and create object initializing the fields with extracted values. If you have multiple records you can create a list of the objects.

user3451261
  • 676
  • 1
  • 7
  • 4
0

this is my entity class

public class userinfo(){
    String name; 
    int gender; ...; 
    Map<String, Map<String, Object>> field;
}

All variables are 'private' type, and getter/setter is essential.