Last active
June 4, 2018 21:20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PuzzleList.java | |
import java.util.Iterator; | |
import java.util.List; | |
public class PuzzleList implements Iterable<Puzzle> { | |
private List<Puzzle> data; | |
public PuzzleList() { | |
super(); | |
} | |
public PuzzleList(List<Puzzle> data) { | |
this.data = data; | |
} | |
public List<Puzzle> getData() { | |
return this.data; | |
} | |
public void setData(List<Puzzle> data) { | |
this.data = data; | |
} | |
public Iterator<Puzzle> iterator() { | |
return data.iterator(); | |
} | |
} | |
// Puzzle.java | |
public class Puzzle { | |
private String created_time; | |
private String message; | |
private String id; | |
public Puzzle() { | |
super(); | |
} | |
public Puzzle(String created_time, String message, String id) { | |
this.created_time = created_time; | |
this.message = message; | |
this.id = id; | |
} | |
public String toString() { | |
return String.format("created_time: %s, message: %s, id: %s", this.created_time, this.message, this.id); | |
} | |
public String getCreated_time() { | |
return this.created_time; | |
} | |
public void setCreated_time(String created_time) { | |
this.created_time = created_time; | |
} | |
public String getMessage() { | |
return this.message; | |
} | |
public void setMessage(String message) { | |
this.message = message; | |
} | |
public String getId() { | |
return this.id; | |
} | |
public void setId(String id) { | |
this.id = id; | |
} | |
} | |
//Main.java | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import java.io.IOException; | |
ObjectMapper mapper = new ObjectMapper(); | |
try { | |
PuzzleList puzzles = mapper.readValue(jsonblob, PuzzleList.class); | |
for (Puzzle puzzle: puzzles) { | |
System.out.println(puzzle); | |
} | |
} catch (IOException e) { | |
System.err.println(e.getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment