JsonUtils { public <T> T deserialize(final String jsonString, final Class<T> type) { try { return OBJECT_MAPPER.readValue(jsonString, type); } catch (IOException e) { LOGGER.error(UNEXPECTED_EXCEPTION, e); return null; } }  T deserializeFromFile(final String fileName, final Class<T> type); String serialize(final T object); T deserialize(final String jsonString, final Class<T> type); C deserialize(final String jsonString, final Class<C> collectionType,
            final Class<T> elementType); JsonNode readJsonNodeFromFile(final String jsonFileName); JsonNode readJsonNodeFromObject(final T object);  }
@Test public void testDeserialize() { Student student = this.jsonUtils.deserialize( "{\"id\":\"S00001\",\"age\":15,\"name\":\"Joe\",\"courses\":[\"Math\",\"Arts\"]}", Student.class); assertStudent(student); }
@Test public void testDeserializeCollectionOfTypedItems() { String studentsAsJson = "[{\"issuer\":\"acs\",\"name\":\"role\",\"value\":\"analyst\"}," + "{\"issuer\":\"acs\",\"name\":\"role\",\"value\":\"admin\"}]"; @SuppressWarnings("unchecked") Set<Attribute> deserialize = this.jsonUtils.deserialize(studentsAsJson, Set.class, Attribute.class); Assert.assertNotNull(deserialize); Assert.assertEquals(deserialize.size(), 2); Iterator<Attribute> iterator = deserialize.iterator(); String value1 = iterator.next().getValue(); String value2 = iterator.next().getValue(); Assert.assertTrue(value1.equals("analyst") || value1.equals("admin")); Assert.assertTrue(value2.equals("analyst") || value2.equals("admin")); }