List of usage examples for com.fasterxml.jackson.databind ObjectMapper writeValueAsString
@SuppressWarnings("resource") public String writeValueAsString(Object value) throws JsonProcessingException
From source file:cn.dataprocess.cfzk.JsonUtil.java
public static String toJsonString(Object sourceObject) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); String ret = mapper.writeValueAsString(sourceObject); mapper = null;//from w ww. j a va2 s. c o m return ret; }
From source file:aot.util.IOUtil.java
public static String serialize(ObjectMapper mapper, Object object) { try {/*from w ww . j ava 2 s . c om*/ return mapper.writeValueAsString(object); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.apache.hadoop.gateway.util.JsonUtils.java
public static String renderAsJsonString(Map<String, Object> map) { String json = null;//from w w w.j a v a2 s. co m ObjectMapper mapper = new ObjectMapper(); try { // write JSON to a file json = mapper.writeValueAsString((Object) map); } catch (JsonProcessingException e) { LOG.failedToSerializeMapToJSON(map, e); } return json; }
From source file:org.hdl.tensorflow.yarn.util.Utils.java
public static String toJsonString(Object object) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.writeValueAsString(object); }
From source file:com.netsteadfast.greenstep.util.JFreeChartDataMapperUtils.java
private static String createUploadData(Map<String, Object> dataMap) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); String jsonData = objectMapper.writeValueAsString(dataMap); return UploadSupportUtils.create(Constants.getSystem(), UploadTypes.IS_TEMP, false, jsonData.getBytes(), SimpleUtils.getUUIDStr() + ".json"); }
From source file:org.jenkinsci.plugins.os_ci.utils.JsonBuilder.java
public static String createJson(Object jsonObj) { String jsonString;/* w w w.j a v a 2 s. co m*/ ObjectMapper mapper = new ObjectMapper(); try { mapper.configure(SerializationFeature.INDENT_OUTPUT, true); jsonString = mapper.writeValueAsString(jsonObj); return jsonString; } catch (JsonGenerationException ex) { ex.printStackTrace(); } catch (JsonMappingException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return null; }
From source file:edu.sjsu.cohort6.esp.common.CommonUtils.java
/** * Converts object to JSON string representation. * It could even be a list of objects which will be converted to JSON array on objects. * * @param object//from ww w . ja va 2 s. c o m * @param <T> * @return * @throws IOException */ public static <T> String convertObjectToJson(T object) throws IOException { final ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(object); }
From source file:com.codemacro.jcm.util.JsonUtil.java
public static String toString(Object obj) { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); String json = ""; try {// w w w . j ava2s.c o m json = mapper.writeValueAsString(obj); } catch (IOException e) { e.printStackTrace(); } return json; }
From source file:com.sugaronrest.restapicalls.methodcalls.Authentication.java
/** * Logs out with the session identifier. * * @param url REST API Url./* w w w .j a v a 2 s . c o m*/ * @param sessionId Session identifier. */ public static void logout(String url, String sessionId) { try { Map<String, String> session = new LinkedHashMap<String, String>(); session.put("user_name", sessionId); ObjectMapper mapper = new ObjectMapper(); String jsonSessionData = mapper.writeValueAsString(session); Map<String, Object> request = new LinkedHashMap<String, Object>(); request.put("method", "logout"); request.put("input_type", "json"); request.put("response_type", "json"); request.put("rest_data", jsonSessionData); Unirest.post(url).fields(request).asString(); } catch (Exception exception) { } }
From source file:fi.luontola.cqrshotel.JsonSerializationTest.java
private static void assertSerializable(Class<?> type, ObjectMapper objectMapper) { try {/* www .j a v a 2 s . c o m*/ Object original = newDummy(type); String json = objectMapper.writeValueAsString(original); Object deserialized = objectMapper.readValue(json, type); assertThat(deserialized, is(original)); } catch (Exception e) { throw new AssertionError("Not serializable: " + type, e); } }