List of usage examples for com.fasterxml.jackson.databind ObjectMapper writeValue
public void writeValue(Writer w, Object value) throws IOException, JsonGenerationException, JsonMappingException
From source file:org.chtijbug.drools.entity.DroolsFactObject.java
public DroolsFactObject(Object realObject, int version) throws IOException { this.realObject = realObject; this.version = version; ObjectMapper mapper = new ObjectMapper(); Writer strWriter = new StringWriter(); mapper.writeValue(strWriter, realObject); this.realObject_JSON = strWriter.toString(); }
From source file:org.fusesource.restygwt.examples.server.GreetingServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("Sending Hello World"); try {//from w w w .j a v a2 s . co m ObjectMapper mapper = new ObjectMapper(); JsonNode helloJsonNode = mapper.readTree(helloWorldJson); mapper.writeValue(resp.getOutputStream(), helloJsonNode); } catch (Throwable e) { e.printStackTrace(); } finally { System.out.flush(); System.err.flush(); } }
From source file:chiliad.parser.pdf.output.JSONOutput.java
@Override public void processPageContent(MPage page) { ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); try {// w w w . jav a 2 s. c o m mapper.writeValue(gen, page); } catch (IOException e) { throw new ParserOutputException("Failed to writer JSON output.", e); } }
From source file:gndata.lib.config.AbstractConfig.java
/** * Serializes the config to json and writes it to a file. The method uses {@link #getFilePath()} * for storing the configuration.//from ww w . j a v a 2 s . co m * * @throws IOException If the storing of the configuration failed. */ public void store() throws IOException { Path tmpPath = Paths.get(filePath); Files.createDirectories(tmpPath.getParent()); try { ObjectMapper mapper = new ObjectMapper().enable(INDENT_OUTPUT).disable(FAIL_ON_EMPTY_BEANS); mapper.writeValue(tmpPath.toFile(), this); } catch (IOException e) { throw new IOException("Unable to write configuration file: " + this.filePath, e); } }
From source file:org.camunda.bpm.debugger.server.protocol.Marshaller.java
public String marshal(Object object) { final ObjectMapper objectMapper = configuration.getObjectMapper(); try {//ww w. j a va2 s . c o m StringWriter valueWriter = new StringWriter(); objectMapper.writeValue(valueWriter, object); return valueWriter.toString(); } catch (Exception e) { throw new DebugWebsocketException("Error while marshalling to JSON ", e); } }
From source file:net.mindengine.galen.api.PageDump.java
public void exportAsJson(File file) throws IOException { makeSureFileExists(file);//from w w w. j a v a 2 s. co m ObjectMapper objectMapper = new ObjectMapper(); objectMapper.writeValue(file, this); }
From source file:ijfx.core.workflow.WorkflowIOTest.java
@Test public void longInterval() throws IOException { LongInterval interval = new DefaultInterval(2, 10, 0, 20); File tmpFile = File.createTempFile("longinterval", ".json"); ObjectMapper mapper = workflowIOService.getObjectMapper(); mapper.writeValue(tmpFile, interval); displayFile(tmpFile);/*from w w w . j av a 2 s . co m*/ LongInterval loaded = mapper.readValue(tmpFile, LongInterval.class); Assert.assertNotNull("loaded interval not null", loaded); Assert.assertEquals("interval equals", loaded, interval); }
From source file:br.unicamp.cst.trafficUnjammer.experiments.communication.JsonHandler.java
/** * Convert an object to String json formatted using GOOGLE GSON API * @param object/*from www .j ava 2 s . co m*/ * @return */ public String fromObjectToJsonData(Object object) { ObjectMapper mapper = new ObjectMapper(); Writer strWriter = new StringWriter(); try { mapper.writeValue(strWriter, object); } catch (JsonGenerationException e) { } catch (JsonMappingException e) { } catch (IOException e) { } String jsonData = strWriter.toString(); return jsonData; }
From source file:nl.ortecfinance.opal.jacksonweb.IncomePlanningSimulationRequestTest.java
@Test public void testIncomePlanningSimulationRequest() throws IOException { IncomePlanningSimulationRequest req = new IncomePlanningSimulationRequest(); req.setStartPeriod(new Date()); ObjectMapper m = new ObjectMapper(); m.writeValue(System.out, req); }
From source file:TDS.Proctor.Web.presentation.taglib.GlobalJavascriptWriter.java
public void writeGlobalAccs() throws IOException { AccsDTO accsDTO = _presenter.getGlobalAccs(); _writer.write("gTDS.globalAccs = "); StringWriter sw = new StringWriter(); ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally mapper.writeValue(sw, accsDTO); sw.close();/*from ww w. j a v a 2s . com*/ _writer.write(sw.toString()); _writer.write(";"); _writer.write("\r\n"); }