List of usage examples for com.fasterxml.jackson.databind ObjectMapper writeValueAsString
@SuppressWarnings("resource") public String writeValueAsString(Object value) throws JsonProcessingException
From source file:codes.thischwa.c5c.filemanager.FilemanagerConfigurationLoaderTest.java
@Test public void testObject() throws Exception { FilemanagerConfig conf = new FilemanagerConfig(); conf.setComment("test"); conf.getOptions().setLang("java"); conf.getOptions().setRelPath(Boolean.FALSE); ObjectMapper mapper = new ObjectMapper(); String actual = mapper.writeValueAsString(conf); String expected = "{\"options\":{\"culture\":null,\"lang\":\"java\",\"theme\":null,\"defaultViewMode\":null,\"autoload\":false,\"showFullPath\":false,\"showTitleAttr\":false,\"browseOnly\":false,\"showConfirmation\":false,\"showThumbs\":false,\"generateThumbnails\":false,\"searchBox\":false,\"listFiles\":false,\"fileSorting\":null,\"dateFormat\":null,\"serverRoot\":false,\"fileRoot\":null,\"relPath\":false,\"logger\":false,\"capabilities\":null,\"plugins\":null,\"chars_only_latin\":false},\"security\":{\"uploadPolicy\":null,\"uploadRestrictions\":null},\"upload\":{\"overwrite\":false,\"imagesOnly\":false,\"fileSizeLimit\":-1},\"exclude\":{\"unallowed_files\":null,\"unallowed_dirs\":null},\"images\":{\"resize\":{\"enabled\":false,\"maxHeight\":0,\"maxWidth\":0},\"imagesExt\":null},\"videos\":{\"showVideoPlayer\":false,\"videosExt\":null,\"videosPlayerHeight\":0,\"videosPlayerWidth\":0},\"audios\":{\"showAudioPlayer\":false,\"audiosExt\":null},\"edit\":{\"enabled\":false,\"lineNumbers\":false,\"lineWrapping\":false,\"codeHighlight\":false,\"theme\":null,\"editExt\":null},\"extras\":{\"extra_js_async\":false,\"extra_js\":null},\"icons\":{\"path\":null,\"directory\":null,\"default\":null},\"customScrollbar\":{\"enabled\":false,\"button\":false,\"theme\":null},\"url\":null,\"_comment\":\"test\"}"; assertEquals(expected, actual);/*from www . j av a 2s .c o m*/ }
From source file:com.spotify.docker.client.messages.EventTest.java
@Test public void serializationRoundTripTest() throws Exception { // Test serializing and deserializing the same Event instance works and preserves data final Event event = Event.create("create", "foo", "nginx", Event.Type.CONTAINER, "create", Event.Actor.create("bar", ImmutableMap.of("image", "nginx", "name", "docker-nginx")), new Date(1487356000), 100L); final ObjectMapper mapper = ObjectMapperProvider.objectMapper(); final String json = mapper.writeValueAsString(event); final Event event2 = mapper.readValue(json, Event.class); assertThat(event, equalTo(event2));//w ww . ja v a 2 s. com }
From source file:eu.cloudwave.wp5.feedbackhandler.controller.AbstractBaseControllerIntegrationTest.java
protected final String expectedResponseBodyOf(final Object object) throws JsonProcessingException { final ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(object); }
From source file:org.hawkular.apm.api.model.PropertyTest.java
@Test public void testJSONSerialisationNumber() { String expected = "{\"name\":\"testprop\",\"value\":\"10.5\",\"type\":\"Number\",\"number\":10.5}"; Property property = new Property(); property.setName("testprop"); property.setValue("10.5"); property.setType(PropertyType.Number); ObjectMapper mapper = new ObjectMapper(); try {//from w w w . j ava2 s . c o m assertEquals(expected, mapper.writeValueAsString(property)); } catch (Exception e) { fail("Failed to serialize: " + e); } }
From source file:com.creditcloud.interestbearing.model.ConfigObjBase.java
public String toJSON() { ObjectMapper mapper = new ObjectMapper(); String json;/* w ww .j av a2s . c o m*/ try { json = mapper.writeValueAsString(this); // return json; } catch (JsonProcessingException ex) { log.error("?{}?JSON?", this, ex); return "{}"; } }
From source file:de.swm.nis.logicaldecoding.gwc.SeedOperationTest.java
@Test public void testCreateSeedOperation() throws JsonProcessingException { GwcSeedDAO seedOperation = new GwcSeedDAO(); SeedRequest seed = new SeedRequest(); seed.setName("testlayer"); seed.setSrs(new Srs(31468)); seed.setThreadCount(2);/*from w w w .jav a 2 s . com*/ seed.setType("reseed"); seed.setFormat("image/png"); seed.setZoomStart(0); seed.setZoomStop(12); Coordinates coords = new Coordinates(); coords.setValues(new double[] { 1.0, 2.0, 3.0, 4.0 }); Bounds bounds = new Bounds(); bounds.setCoords(coords); seed.setBounds(bounds); seedOperation.setSeedRequest(seed); ObjectMapper mapper = new ObjectMapper(); String result = mapper.writeValueAsString(seedOperation); System.out.println(result); }
From source file:com.vmware.photon.controller.api.client.resource.AuthApiTest.java
@Test public void testGetAuthStatus() throws IOException { final Auth auth = new Auth(); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(auth); setupMocks(serialized, HttpStatus.SC_OK); AuthApi authApi = new AuthApi(restClient); Auth response = authApi.getAuthStatus(); assertEquals(response, auth);//from www .j a v a 2 s . c om }
From source file:com.vmware.photon.controller.api.client.resource.AuthRestApiTest.java
@Test public void testGetAuthStatus() throws IOException { final Auth auth = new Auth(); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(auth); setupMocks(serialized, HttpStatus.SC_OK); AuthApi authApi = new AuthRestApi(restClient); Auth response = authApi.getAuthStatus(); assertEquals(response, auth);/* ww w .ja v a2s. co m*/ }
From source file:hola.ControladorUsuario.java
@RequestMapping(value = "/usuario", method = RequestMethod.GET, headers = { "Accept=application/json" }) @ResponseBody/*from w w w.java 2 s. co m*/ String guardar() throws Exception { ArrayList<Usuario> usuarios = new ArrayList<Usuario>(); DAOUsuario dao = new DAOUsuario(); usuarios = dao.buscarTodos(); ObjectMapper maper = new ObjectMapper(); return maper.writeValueAsString(usuarios); }
From source file:org.bdlions.response.ResultEvent.java
@Override public String toString() { ObjectMapper mapper = new ObjectMapper(); String json = ""; try {//from w w w. j a v a2s .co m json = mapper.writeValueAsString(this); } catch (Exception ex) { logger.error(ex.getMessage()); } return json; }