List of usage examples for com.fasterxml.jackson.databind ObjectMapper ObjectMapper
public ObjectMapper()
From source file:com.shampan.db.collections.fragment.profile.Religion.java
public static Religion getReligionInfo(String jsonContent) { Religion religion = null;/* w w w. j a va2 s . c o m*/ try { ObjectMapper mapper = new ObjectMapper(); religion = mapper.readValue(jsonContent, Religion.class); } catch (Exception ex) { ex.printStackTrace(); } return religion; }
From source file:com.world.watch.worldwatchcron.util.PushToUser.java
public static void push(List<String> data, String userId) { try {//from ww w .ja v a2 s . c o m InputStream jsonStream = PushToUser.class.getResourceAsStream("/parsePush.json"); ObjectMapper mapper = new ObjectMapper(); PushData push = mapper.readValue(jsonStream, PushData.class); push.getWhere().setUsername(userId); push.getData().setKeywords(data); String json = mapper.writeValueAsString(push); HttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().build()) .build(); HttpPost post = new HttpPost(URL); post.setHeader("X-Parse-Application-Id", "WhqWj009luOxOtIH3rM9iWJICLdf0NKbgqdaui8Q"); post.setHeader("X-Parse-REST-API-Key", "lThhKObAz1Tkt092Cl1HeZv4KLUsdATvscOaGN2y"); post.setHeader("Content-Type", "application/json"); logger.debug("JSON to push {}", json.toString()); StringEntity strEntity = new StringEntity(json); post.setEntity(strEntity); httpClient.execute(post); logger.debug("Pushed {} to userId {}", data.toString(), userId); } catch (Exception ex) { logger.error("Push Failed for {} ", userId, ex); } }
From source file:org.pathirage.freshet.utils.ExpressionSerde.java
public static String serialize(Expression expression) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); StringWriter sw = new StringWriter(); objectMapper.writeValue(sw, expression); return sw.toString(); }
From source file:io.fabric8.kubernetes.client.internal.PatchUtils.java
public static ObjectMapper patchMapper() { if (patchMapper == null) { patchMapper = new ObjectMapper(); patchMapper.addMixInAnnotations(ObjectMeta.class, ObjectMetaMixIn.class); patchMapper.addMixInAnnotations(Build.class, BuildMixIn.class); }//from w w w . j a v a 2s . c o m return patchMapper; }
From source file:persistence.ContactPersistence.java
public static void updateContact(String id, Contact contact) throws IOException { ObjectMapper mapper = new ObjectMapper(); String data = mapper.writeValueAsString(contact); JestConfig.updateData(typeName, id, data); }
From source file:fi.helsinki.opintoni.web.WebTestUtils.java
public static byte[] toJsonBytes(Object object) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.registerModule(new JavaTimeModule()); return mapper.writeValueAsBytes(object); }
From source file:eu.europa.ec.fisheries.uvms.notifications.NotificationUtils.java
public static String getTextMessage(NotificationMessage message) throws JsonProcessingException { return new ObjectMapper().writeValueAsString(message.getProperties()); }
From source file:org.moneta.utils.JsonUtils.java
/** * Will convert the given object to Json format. * @param jsonObject//from w w w. j a v a2 s . c o m * @return jsonText */ public static String serialize(Object jsonObject) { Validate.notNull(jsonObject, "Null object cannot be converted to Json"); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(jsonObject); } catch (Exception e) { throw new MonetaException("Error converting object to Json", e).addContextValue("object", jsonObject); } }
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 {//from ww w. ja v a2s . c o m json = mapper.writeValueAsString(obj); } catch (IOException e) { e.printStackTrace(); } return json; }
From source file:AIR.Common.Json.JsonHelper.java
public static <T> String serialize(T obj) throws JsonGenerationException, JsonMappingException, IOException { if (obj == null) return null; ObjectMapper mapper = new ObjectMapper(); String json = null;//from w ww . ja va 2 s. co m StringWriter sw = new StringWriter(); mapper.writeValue(sw, obj); json = sw.toString(); sw.close(); return json; }