简体   繁体   中英

How to have dynamic data type variable in Java data model class?

An API response will send different data type value in different situation. I am using Gson parser to parse json response string. eg:

1. { "value" : 1 }
2. { "value" : "Hello" }
3. { "value" : { "name" : "name", "email" : "" } }

You can use Map<String, Object> and then manually check where value is digit, String or nested Map

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