### Question:
OAuthJSONProvider implements MessageBodyWriter<Object>,
    MessageBodyReader<Object> { public void writeTo(Object obj, Class<?> cls, Type t, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { if (obj instanceof ClientAccessToken) { writeAccessToken((ClientAccessToken)obj, os); } else if (obj instanceof TokenIntrospection) { writeTokenIntrospection((TokenIntrospection)obj, os); } else { writeOAuthError((OAuthError)obj, os); } }  long getSize(Object obj, Class<?> clt, Type t, Annotation[] anns, MediaType mt); boolean isWriteable(Class<?> cls, Type t, Annotation[] anns, MediaType mt); void writeTo(Object obj, Class<?> cls, Type t, Annotation[] anns, MediaType mt,
                        MultivaluedMap<String, Object> headers, OutputStream os); boolean isReadable(Class<?> cls, Type t, Annotation[] anns, MediaType mt); Object readFrom(Class<Object> cls, Type t, Annotation[] anns,
                           MediaType mt, MultivaluedMap<String, String> headers, InputStream is); Map<String, String> readJSONResponse(InputStream is);  }### Answer:
@Test public void testWriteBearerClientAccessToken() throws Exception { ClientAccessToken token = new ClientAccessToken(OAuthConstants.BEARER_TOKEN_TYPE, "1234"); token.setExpiresIn(12345); token.setRefreshToken("5678"); token.setApprovedScope("read"); token.setParameters(Collections.singletonMap("my_parameter", "http: OAuthJSONProvider provider = new OAuthJSONProvider(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); provider.writeTo(token, ClientAccessToken.class, ClientAccessToken.class, new Annotation[]{}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos); doReadClientAccessToken(bos.toString(), OAuthConstants.BEARER_TOKEN_TYPE, token.getParameters()); }
@Test public void testWriteHawkClientAccessToken() throws Exception { ClientAccessToken token = new ClientAccessToken("hawk", "1234"); token.setExpiresIn(12345); token.setRefreshToken("5678"); token.setApprovedScope("read"); Map<String, String> params = new LinkedHashMap<>(); params.put(OAuthConstants.HAWK_TOKEN_KEY, "test_mac_secret"); params.put(OAuthConstants.HAWK_TOKEN_ALGORITHM, OAuthConstants.HMAC_ALGO_SHA_1); params.put("my_parameter", "http: token.setParameters(params); OAuthJSONProvider provider = new OAuthJSONProvider(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); provider.writeTo(token, ClientAccessToken.class, ClientAccessToken.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos); doReadClientAccessToken(bos.toString(), OAuthConstants.HAWK_TOKEN_TYPE, params); }