Firstly forgive me as I think this is a stupid question. I just started learning java
I have a json file of which I parsed it to POJO so that I can do operations on them
this is the parser implementation
public class ParsingTweet {
public static void main(String[] args) throws IOException {
assert args != null & args.length > 0;
List<Tweet> tweets = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
try (BufferedReader reader = new BufferedReader(new FileReader(args[0]))) {
String line;
while ((line = reader.readLine()) != null) {
tweets.add(mapper.readValue(line, Tweet.class));
}
}
System.out.println(tweets);
}
}
but my instructor said this result is not the actual POJO. its just a string representation. For example
[[text = I think this would be good. Would hopefully light the fire in the later rounds if you knew you were losing..., created_at = Mon Mar 06 22:48:07 +0000 2017, user = User@56f4468b, coordinates = null], [text = @Night_0f_Fire He's stuck in the alimony machine,, bust him out, created_at = Mon Mar 06 22:47:53 +0000 2017, user = User@6cc4c815, coordinates = null], ..., ..., ...]]]
so what does the actual POJO look like?
PS. this is the example json
{"text": "Flood/Storm/Tree Down. Northern Beaches (King Rd, Ingleside, NSW 2101) at 6 Mar 2017 21:38 , "user": {"id": "4721717942", "name": "NSW Fire Updates"}, "lang": "en", "coordinates": { "coordinates": [151.264811, -33.6848] , "type":"Point"}, "created_at": "Mon Mar 06 10:44:31 +0000 2017"}, ..., ...
Use Gson for example.
String fullFile = ...read file...;
Gson gson = new Gson();
List<Tweet> tweets = gson.fromJson(fullFile, new TypeToken<ArrayList<Tweet>>(){});
System.out.println(tweets);
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.