List of usage examples for com.fasterxml.jackson.databind ObjectMapper writeValueAsString
@SuppressWarnings("resource") public String writeValueAsString(Object value) throws JsonProcessingException
From source file:org.hawkular.qe.wildfly.management.subsystem.Datasources.java
public boolean addDataSource(DataSource dataSource) { ObjectMapper mapper = new ObjectMapper(); try {// ww w. j a v a 2s .co m ModelNode op = ModelNode.fromJSONString(mapper.writeValueAsString(dataSource)); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ModelNode address = op.get(ModelDescriptionConstants.ADDRESS); address.add(ModelDescriptionConstants.SUBSYSTEM, Datasources.DATASOURCES); address.add(DATA_SOURCE, dataSource.getName()); ModelNode result = StandaloneMgmtClient.execute(modelControllerClient, op); return result.get(ModelDescriptionConstants.OUTCOME).asString().equalsIgnoreCase("success"); } catch (JsonProcessingException ex) { _logger.error("Error, ", ex); } return false; }
From source file:com.netflix.genie.common.model.Auditable.java
/** * Convert this object to a string representation. * * @return This application data represented as a JSON structure *//* w w w .j a v a 2s. c om*/ @Override public String toString() { try { final ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(this); } catch (final JsonProcessingException ioe) { LOG.error(ioe.getLocalizedMessage(), ioe); return ioe.getLocalizedMessage(); } }
From source file:com.surfs.storage.block.service.impl.ExportServiceImpl.java
@Override public String addRemoteDevice(Map<String, Object> args) { String ip = args.get("ip").toString(); /*String device = args.get("device"); String target = args.get("target");*/ try {//from ww w . ja v a 2 s . co m ObjectMapper objectMapper = new ObjectMapper(); String json = objectMapper.writeValueAsString(args); LogFactory.info(json); String url = HttpUtils.getUrl(ip, Constant.REST_SERVICE_PORT, BlockConstant.POOL_SERVICE_PATH, BlockConstant.EXPORT_SERVICE_ADDDEVICE_NAME); return HttpUtils.invokeHttpForGet(url, json); } catch (IOException e) { LogFactory.error(e.getMessage()); } return null; }
From source file:org.zalando.jackson.datatype.money.MonetaryAmountSerializerTest.java
@Test public void shouldSerializeWithoutFormattedValueIfFactoryProducesNull() throws JsonProcessingException { final ObjectMapper unit = new ObjectMapper().registerModule(new MoneyModule()); final String expected = "{\"amount\":29.95,\"currency\":\"EUR\"}"; final String actual = unit.writeValueAsString(Money.of(29.95, "EUR")); assertThat(actual, is(expected));/* w w w. j a v a2 s.co m*/ }
From source file:com.econcept.webservice.rest.UserResource.java
@GET public Response getUser() { ResponseBuilder lBuilder = null;/*from ww w.j ava2s .c o m*/ try { UserAccount lUserAccount = getUserAccount(); ObjectMapper lMapper = new ObjectMapper(); lBuilder = Response.status(Status.OK).entity(lMapper.writeValueAsString(lUserAccount)); LOGGER.debug(lMapper.writeValueAsString(lUserAccount)); } // try catch (Exception pException) { LOGGER.debug(pException.toString()); lBuilder = Response.status(Status.INTERNAL_SERVER_ERROR).entity(pException); } // catch return lBuilder.build(); }
From source file:com.helpmobile.test.RestTest.java
@Test public void testAWorkshop() throws Exception { ObjectMapper mapper = new ObjectMapper(); RestAccess restAccess = new RestAccess(); WorkshopList data = restAccess.getWorkshopList(3); String json = mapper.writeValueAsString(data); System.out.println(json);/*from w ww.j a v a 2s . c o m*/ }
From source file:org.smartparam.manager.json.integration.JacksonSerializerFactory.java
private Serializer jackson() { final ObjectMapper jackson = ParamEngineJacksonEnhancer.createEnhanced(); return new Serializer() { @Override/*w ww. j a v a2s. c o m*/ public String serialize(Object object) { try { return jackson.writeValueAsString(object); } catch (JsonProcessingException ex) { throw new RuntimeException(ex); } } }; }
From source file:datadidit.helpful.hints.processors.csv.converter.ConvertCSVToJSON.java
public String writeAsJson(List<Map<?, ?>> data) throws IOException { ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(data); }
From source file:com.miage.ws.WebServiceDomotique.java
private String getJsonFromObject(Object o) { ObjectMapper mapper = new ObjectMapper(); try {// ww w . j av a 2s . c o m return mapper.writeValueAsString(o); } catch (JsonProcessingException ex) { Logger.getLogger(WebServiceDomotique.class.getName()).log(Level.SEVERE, null, ex); return ex.getMessage(); } }
From source file:org.commonjava.maven.cartographer.dto.PomRecipeTest.java
@Test public void jsonRoundTrip_GraphCompOnly() throws Exception { final PomRequest recipe = PomRequestBuilder.newPomRequestBuilder() .withGraphs(GraphCompositionBuilder.newGraphCompositionBuilder() .withGraph(GraphDescriptionBuilder.newGraphDescriptionBuilder() .withRoots(new SimpleProjectVersionRef("org.foo", "bar", "1")).build()) .build())//from w ww.j av a 2s.c o m .build(); final Cartographer carto = new CartographerCoreBuilder(temp.newFolder(), new FileNeo4jConnectionFactory(temp.newFolder(), false)).build(); final ObjectMapper mapper = carto.getObjectMapper(); logger.debug("Testing PomRequest serialization with {}", mapper); logger.info("request: {}", recipe); final String json = mapper.writeValueAsString(recipe); logger.info("JSON: {}", json); final PomRequest result = mapper.readValue(json, PomRequest.class); assertThat(result.getGraphComposition(), equalTo(recipe.getGraphComposition())); }