/** Creates the entity by parsing the root node and all the children. */ public SinaContainer(JsonNode rootNode) throws JsonParseException, JsonMappingException, IOException { this.id = rootNode.get("id").longValue(); this.receivedAt = DateTimeFormat.forPattern(RECEIVED_DATETIME_PATTERN) .parseDateTime(rootNode.get("received_at").textValue()); JsonNode textNode = rootNode.get("text"); this.rawContents = rootNode.toString(); this.eventType = EventType.getByName(textNode.get("type").textValue()); this.event = textNode.get("event").toString(); // TODO: define what to do with DELETE messages this.matchInfoKeyword = rootNode.get("match_info") == null ? null : rootNode.get("match_info").get("keyword").textValue(); this.matchInfoUid = rootNode.get("match_info") == null ? null : rootNode.get("match_info").get("uid").longValue(); ObjectMapper mapper = SinaWeiboParser.getObjectMapper(); JsonParser parser; switch (eventType) { case COMMENT: parser = textNode.get("comment").traverse(mapper); this.contentNode = parser.readValueAs(SinaCommentNode.class); break; case STATUS: parser = textNode.get("status").traverse(mapper); this.contentNode = parser.readValueAs(SinaStatusNode.class); break; } }