try {
Reader reader = new InputStreamReader(stream, Charsets.UTF_8);
String jsonString = CharStreams.toString(reader);
stream.close();
Factory factory = AutoBeanFactorySource.create(Factory.class);
RestApiService service =
AutoBeanCodex.decode(factory, RestApiService.class, jsonString).as();
return service;
} catch (IOException e) {
fail("IOException: " + e.getMessage());