简体   繁体   中英

Convert JSON object into java class object

I have JSONObject having date field which I want to convert into Class object.

I am using Object Mapper() but while parsing I am getting error.

JSONObject caseDetailsJson = method which returns JSONObject;

ObjectMapper mapper = new ObjectMapper(); mapper.setDateFormat(apiDateFormat);

While getting class object : ABC abc = mapper.readValue(caseDetailsJson.toJSONString(), ABC.class);

I am getting exception because of date parameter in JSON since date value does not has "" and it takes only starting word.

For example : Date value is :"dateCollected":Fri Jul 07 00:00:00 IST 1989,

but its taking only Fri and not whole date.

The date format does not appear to be standard.

You use mapper.setDateFormat(apiDateFormat); . Try using a proper date format that will match your string format.

You did not provide enough details, and code samples would be welcomed for more accurate answers.

If your date value is not double quoted, it is not JSON as specified. Have a look at here: https://tools.ietf.org/html/rfc7159 or here http://json.org/

I'm afraid you have to tweak your input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM