### Question:
JSONSerialisation { public <T> T deserialise(String text, Class<T> clazz) { try { T value = mapper.readValue(text, clazz); return value; } catch (IOException e) { throw new IllegalStateException( MessageFormat.format( "Failed to deserailise {0}", clazz.getSimpleName()), e); } } @Inject  JSONSerialisation(@Named(CoreTokenConstants.OBJECT_MAPPER) ObjectMapper mapper); String serialise(T object); T deserialise(String text, Class<T> clazz); static String jsonAttributeName(String name);  }### Answer:
@Test public void tokenRestrictionDeserialisationWithTypeWorks() throws Exception { InternalSession is = serialization.deserialise(getJSON("/json/basic-session-with-restriction.json"), InternalSession.class); assertThat(is).isNotNull(); TokenRestriction restriction = is.getRestrictionForToken(new SessionID("AQIC5wM2LY4SfcyTLz6VjQ7nkFeDcEh8K5dXkIE" + "NpXlpg28.*AAJTSQACMDIAAlMxAAIwMQACU0sAEzc5ODIzMDM5MzQyNzU2MTg1NDQ.*")); assertThat(restriction).isNotNull().isInstanceOf(DNOrIPAddressListTokenRestriction.class); assertThat(restriction.toString().equals("Fzy2GsI/O1TsXhvlVuqjqIuTG2k=")); assertThat(is.getSessionHandle()).isNotNull().isEqualTo("shandle:weasel"); }
@Test(dataProvider = "complex") public void internalSessionDeserialisationWorks(String path) throws Exception { InternalSession is = serialization.deserialise(getJSON(path), InternalSession.class); assertThat(is).isNotNull(); assertThat(is.getID()).isNotNull(); assertThat(Collections.list(is.getPropertyNames())).hasSize(23); assertThat(is.getSessionHandle()).isNotNull(); }
@Test(dataProvider = "complex") public void internalSessionDeserialisationDoesNotModifyMapTypes(String path) throws Exception { InternalSession is = serialization.deserialise(getJSON(path), InternalSession.class); assertThat(is).isNotNull(); checkMapType(is, "sessionEventURLs"); checkMapType(is, "restrictedTokensBySid"); checkMapType(is, "restrictedTokensByRestriction"); }