List of usage examples for com.fasterxml.jackson.databind ObjectMapper ObjectMapper
public ObjectMapper()
From source file:com.meltmedia.jackson.crypto.Defaults.java
public static ObjectMapper defaultObjectMapper(ObjectMapper mapper) { if (mapper != null) return mapper; return new ObjectMapper(); }
From source file:com.alzatezabala.fp.presentacion.json.JSONConverterImplJackson.java
@Override public Object fromJSON(String json, Class clazz) { try {//from ww w .ja v a 2s . c om ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.readValue(json, clazz); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:util.TestUtil.java
/** * Converts an object to json (as bytes). * * @param object the object to convert/*from w ww . j ava 2 s. com*/ * @return JSON as bytes. * @throws JsonProcessingException thrown by jackson objectmapper */ public static byte[] toJson(BaseEntity object) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsBytes(object); }
From source file:es.cursohibernate.spring.json.JsonTransformerImplJackson.java
@Override public Object fromJson(String json, Class clazz) { try {/*from www . j ava 2 s . co m*/ ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.readValue(json, clazz); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:dk.lnj.swagger4ee.AbstractJSonTest.java
public void makeCompare(SWRoot root, String expFile) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); // make deserializer use JAXB annotations (only) mapper.setAnnotationIntrospector(introspector); // make serializer use JAXB annotations (only) StringWriter sw = new StringWriter(); mapper.writeValue(sw, root);/*from ww w. j a v a 2 s . c o m*/ mapper.writeValue(new FileWriter(new File("lasttest.json")), root); String actual = sw.toString(); String expected = new String(Files.readAllBytes(Paths.get(expFile))); String[] exp_split = expected.split("\n"); String[] act_split = actual.split("\n"); for (int i = 0; i < exp_split.length; i++) { String exp = exp_split[i]; String act = act_split[i]; String shortFileName = expFile.substring(expFile.lastIndexOf("/")); Assert.assertEquals(shortFileName + ":" + (i + 1), superTrim(exp), superTrim(act)); } }
From source file:org.apache.nifi.minifi.integration.util.LogUtil.java
public static void verifyLogEntries(String expectedJsonFilename, Container container) throws Exception { List<ExpectedLogEntry> expectedLogEntries; try (InputStream inputStream = LogUtil.class.getClassLoader().getResourceAsStream(expectedJsonFilename)) { List<Map<String, Object>> expected = new ObjectMapper().readValue(inputStream, List.class); expectedLogEntries = expected.stream() .map(map -> new ExpectedLogEntry(Pattern.compile((String) map.get("pattern")), (int) map.getOrDefault("occurrences", 1))) .collect(Collectors.toList()); }/*from w w w. jav a2 s. c o m*/ DockerPort dockerPort = container.port(8000); URL url = new URL("http://" + dockerPort.getIp() + ":" + dockerPort.getExternalPort()); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); try (InputStream inputStream = urlConnection.getInputStream(); InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { String line; for (ExpectedLogEntry expectedLogEntry : expectedLogEntries) { boolean satisfied = false; int occurrences = 0; while ((line = bufferedReader.readLine()) != null) { if (expectedLogEntry.pattern.matcher(line).find()) { logger.info("Found expected: " + line); if (++occurrences >= expectedLogEntry.numOccurrences) { logger.info("Found target " + occurrences + " times"); satisfied = true; break; } } } if (!satisfied) { fail("End of log reached without " + expectedLogEntry.numOccurrences + " match(es) of " + expectedLogEntry.pattern); } } } finally { urlConnection.disconnect(); } }
From source file:com.cirro.jsonjoin.utils.FileManager.java
public static void saveResults(List<ResponseRow> result, String path) throws IOException { new ObjectMapper().writeValue(new File(path), result); }
From source file:com.codenvy.eclipse.core.CodenvyProjectDescriptor.java
public static CodenvyProjectDescriptor load(IProject project) { final IFile projectDescriptor = project.getFolder(CODENVY_FOLDER_NAME) .getFile(PROJECT_DESCRIPTOR_FILE_NAME); if (projectDescriptor.exists()) { final ObjectMapper mapper = new ObjectMapper(); try {//from w ww . jav a2s .c om return mapper.readValue(projectDescriptor.getContents(), CodenvyProjectDescriptor.class); } catch (IOException | CoreException e) { throw new RuntimeException(e); } } return null; }
From source file:com.shampan.db.collections.fragment.status.Comment.java
public static Comment getStatusComment(String jsonContent) { Comment commentInfo = null;//from ww w. ja v a 2 s . c o m try { ObjectMapper mapper = new ObjectMapper(); commentInfo = mapper.readValue(jsonContent, Comment.class); } catch (Exception ex) { ex.printStackTrace(); } return commentInfo; }
From source file:edu.sjsu.cohort6.esp.common.CommonUtils.java
/** * Converts a JSON array of objects to List of Java Object types. * For example, convert a JSON array of students to List<Student>. * * @param jsonArrayStr//from w ww . j av a 2 s . c om * @param clazz * @param <T> * @return * @throws java.io.IOException */ public static <T> List<T> convertJsonArrayToList(String jsonArrayStr, Class<T> clazz) throws java.io.IOException { ObjectMapper mapper = new ObjectMapper(); //jsonArrayStr = removeIdField(jsonArrayStr); return mapper.readValue(jsonArrayStr, TypeFactory.defaultInstance().constructCollectionType(List.class, clazz)); }