RoomDeserializer extends JsonChatDeserializer<Room> { @Override public Room deserialize(JsonParser jp, DeserializationContext context) throws IOException, JsonProcessingException { ObjectCodec oc = jp.getCodec(); JsonNode node = oc.readTree(jp); String roomId = node.get("id").asText(); String name = node.get("name").asText(); String topic = node.get("topic").get("value").asText(); DateTime creationDate = new DateTime(node.get("created").asLong() * 1000L); String ownerUserId = node.get("creator").asText(); boolean archived = node.get("is_archived").asBoolean(); boolean privateRoom = roomId.startsWith("G"); return new Room(roomId, name, topic, null, creationDate, ownerUserId, archived, privateRoom, null, null); }  @Override Room deserialize(JsonParser jp, DeserializationContext context);  }
@Test public void testDeserialize() throws Exception { Room r = objMapper.readValue(roomJsonStr, Room.class); assertEquals("C024BE91L", r.getRoomId()); assertEquals(new DateTime(1360782804L * 1000), r.getCreationDate()); assertEquals("fun", r.getName()); assertEquals("U024BE7LH", r.getOwnerUserId()); assertEquals("C024BE91L", r.getRoomId()); assertEquals("Fun times", r.getTopic()); assertTrue(r.isArchived()); assertFalse(r.isPrivateRoom()); assertNull(r.getXmppJid()); assertNull(r.getGuestAccessURL()); assertNull(r.getLastActiveDate()); r = objMapper.readValue(privateRoomJsonStr, Room.class); assertEquals("G024BE91L", r.getRoomId()); assertEquals(new DateTime(1360782804L * 1000), r.getCreationDate()); assertEquals("fun", r.getName()); assertEquals("U024BE7LH", r.getOwnerUserId()); assertEquals("G024BE91L", r.getRoomId()); assertEquals("Fun times", r.getTopic()); assertTrue(r.isArchived()); assertTrue(r.isPrivateRoom()); assertNull(r.getXmppJid()); assertNull(r.getGuestAccessURL()); assertNull(r.getLastActiveDate()); }