List of usage examples for com.fasterxml.jackson.databind ObjectMapper readValue
@SuppressWarnings("unchecked") public <T> T readValue(byte[] src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
From source file:org.apache.htrace.impl.HTracedProcess.java
private static StartupNotificationData readStartupNotification(ServerSocket listener) throws IOException { Socket socket = listener.accept(); try {/* w ww . ja va 2 s .co m*/ InputStream in = socket.getInputStream(); ObjectMapper objectMapper = new ObjectMapper(); StartupNotificationData data = objectMapper.readValue(in, StartupNotificationData.class); return data; } finally { socket.close(); } }
From source file:cn.org.once.cstack.cli.rest.JsonConverter.java
public static List<LogUnit> getLogUnit(String response) { List<LogUnit> logUnits = new ArrayList<LogUnit>(); ObjectMapper mapper = new ObjectMapper(); try {/*from w ww .ja v a2s . co m*/ logUnits = mapper.readValue(response, new TypeReference<List<LogUnit>>() { }); } catch (IOException e) { e.printStackTrace(); } return logUnits; }
From source file:cn.org.once.cstack.cli.rest.JsonConverter.java
public static List<Command> getCommands(String response) { List<Command> commands = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); try {// w ww .j a v a 2 s.c o m commands = mapper.readValue(response, new TypeReference<List<Command>>() { }); } catch (IOException e) { e.printStackTrace(); } return commands; }
From source file:io.github.retz.scheduler.MesosHTTPFetcher.java
static List<Map<String, Object>> parseTasks(InputStream in, String frameworkId) throws IOException { ObjectMapper mapper = new ObjectMapper(); List<Map<String, Object>> ret = new LinkedList<>(); Map<String, List<Map<String, Object>>> map = mapper.readValue(in, Map.class); List<Map<String, Object>> tasks = map.get("tasks"); for (Map<String, Object> task : tasks) { String fid = (String) task.get("framework_id"); if (!frameworkId.equals(fid)) { continue; }//from w w w .j a va2 s . co m ret.add(task); } return ret; }
From source file:cn.org.once.cstack.cli.rest.JsonConverter.java
public static List<Snapshot> getSnapshot(String response) { List<Snapshot> snapshots = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); try {// w w w . jav a 2 s .com snapshots = mapper.readValue(response, new TypeReference<List<Snapshot>>() { }); } catch (IOException e) { e.printStackTrace(); } return snapshots; }
From source file:cn.org.once.cstack.cli.rest.JsonConverter.java
public static List<FileUnit> getFileUnits(String response) { List<FileUnit> fileUnits = new ArrayList<FileUnit>(); ObjectMapper mapper = new ObjectMapper(); try {/*from w w w. ja va 2 s . c o m*/ fileUnits = mapper.readValue(response, new TypeReference<List<FileUnit>>() { }); } catch (IOException e) { e.printStackTrace(); } return fileUnits; }
From source file:cn.org.once.cstack.cli.rest.JsonConverter.java
public static Application getApplication(String response) { Application application = new Application(); ObjectMapper mapper = new ObjectMapper(); try {/*ww w . java 2s. co m*/ application = mapper.readValue(response, Application.class); } catch (IOException e) { e.printStackTrace(); } return application; }
From source file:com.zxy.commons.json.JsonUtils.java
/** * json?/* w w w. j a v a2s . co m*/ * * @param <T> This is the type parameter * @param include include * @param jsonString json * @param clazz * @return */ public static <T> T toObject(JsonInclude.Include include, String jsonString, Class<T> clazz) { try { ObjectMapper mapper = getObjectMapper(include); return mapper.readValue(jsonString, TypeFactory.defaultInstance().constructType(clazz)); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:ch.ralscha.extdirectspring_itest.InfoServiceTest.java
@SuppressWarnings("unchecked") private static void testInfoPost(String method) throws IOException { CloseableHttpClient client = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; try {//from w ww . java2 s . co m HttpPost post = new HttpPost("http://localhost:9998/controller/router"); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("extTID", "1")); formparams.add(new BasicNameValuePair("extAction", "infoService")); formparams.add(new BasicNameValuePair("extMethod", method)); formparams.add(new BasicNameValuePair("extType", "rpc")); formparams.add(new BasicNameValuePair("extUpload", "false")); formparams.add(new BasicNameValuePair("userName", "RALPH")); UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formparams, "UTF-8"); post.setEntity(postEntity); response = client.execute(post); HttpEntity entity = response.getEntity(); assertThat(entity).isNotNull(); String responseString = EntityUtils.toString(entity); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> rootAsMap = mapper.readValue(responseString, Map.class); assertThat(rootAsMap).hasSize(5); assertThat(rootAsMap.get("method")).isEqualTo(method); assertThat(rootAsMap.get("type")).isEqualTo("rpc"); assertThat(rootAsMap.get("action")).isEqualTo("infoService"); assertThat(rootAsMap.get("tid")).isEqualTo(1); Map<String, Object> result = (Map<String, Object>) rootAsMap.get("result"); assertThat(result).hasSize(2); assertThat(result.get("user-name-lower-case")).isEqualTo("ralph"); assertThat(result.get("success")).isEqualTo(Boolean.TRUE); } finally { IOUtils.closeQuietly(response); IOUtils.closeQuietly(client); } }
From source file:cn.org.once.cstack.cli.rest.JsonConverter.java
public static List<Application> getApplications(String response) { List<Application> applications = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); try {// w w w . ja v a 2 s .co m applications = mapper.readValue(response, new TypeReference<List<Application>>() { }); } catch (IOException e) { e.printStackTrace(); } return applications; }