List of usage examples for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion
public ObjectMapper setSerializationInclusion(JsonInclude.Include incl)
From source file:com.ucrisko.libroomreserve.config.WebAppConfig.java
@Bean public ObjectMapper jacksonObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(Include.NON_NULL); return objectMapper; }
From source file:com.fitbur.docker.client.internal.ObjectMapperProvider.java
@PerLookup @Override/* w ww .ja va 2s . c om*/ public ObjectMapper provide() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY) .setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(MapperFeature.USE_ANNOTATIONS).enable(MapperFeature.AUTO_DETECT_GETTERS) .enable(MapperFeature.AUTO_DETECT_SETTERS).enable(MapperFeature.AUTO_DETECT_IS_GETTERS) .enable(MapperFeature.AUTO_DETECT_FIELDS).enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS); mapper.disable(SerializationFeature.INDENT_OUTPUT).enable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS) .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.disable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true) .configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true); return mapper; }
From source file:org.finra.herd.swaggergen.AbstractTest.java
protected String toYaml(Object object) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); objectMapper.setSerializationInclusion(Include.NON_EMPTY); objectMapper.setSerializationInclusion(Include.NON_NULL); return objectMapper.writeValueAsString(object); }
From source file:com.amazonaws.dynamodb.bootstrap.AttributeValueMixInTest.java
/** * Test the Mixin to make sure that it capitalizes the values, and is * different from an ObjectMapper without the Mixin. *//*from ww w. j a v a 2s. com*/ @Test public void testReturnsCapitalSWithMixin() throws JsonProcessingException { String capitalS = "S"; String lowercaseS = "s"; ObjectMapper mapperWith = new ObjectMapper(); mapperWith.setSerializationInclusion(Include.NON_NULL); mapperWith.addMixInAnnotations(AttributeValue.class, AttributeValueMixIn.class); String withMixIn = mapperWith.writeValueAsString(sampleScanResult().get(0)); ObjectMapper mapperWithout = new ObjectMapper(); mapperWithout.setSerializationInclusion(Include.NON_NULL); String withoutMixIn = mapperWithout.writeValueAsString(sampleScanResult().get(0)); assertTrue(withMixIn.contains(capitalS)); assertTrue(withoutMixIn.contains(lowercaseS)); }
From source file:com.flipkart.bifrost.SampleUsageTest.java
@Test public void testSendReceive() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); Connection connection = new Connection(Lists.newArrayList("localhost"), "guest", "guest"); connection.start();//from w w w.j a va 2s .c o m //Create executor BifrostExecutor<Map<String, Object>> executor = BifrostExecutor .<Map<String, Object>>builder(HttpCallCommand.class).connection(connection).objectMapper(mapper) .requestQueue("bifrost-send").responseQueue("bifrost-recv") .executorService(Executors.newFixedThreadPool(10)).responseWaitTimeout(20000).build(); //Create execution server BifrostRemoteCallExecutionServer<Map<String, Object>> executionServer = BifrostRemoteCallExecutionServer .<Map<String, Object>>builder(HttpCallCommand.class).objectMapper(mapper).connection(connection) .concurrency(10).requestQueue("bifrost-send").build(); executionServer.start(); //Start making calls RemoteCallable<Map<String, Object>> callable = HttpCallCommand.createGet("http://jsonip.com/"); Future<Map<String, Object>> result = executor.submit(callable); Map<String, Object> r = result.get(); //Shutdown exverything when done executor.shutdown(); executionServer.stop(); connection.stop(); Assert.assertTrue(r.containsKey("ip")); }
From source file:de.javagl.jgltf.model.io.GltfWriter.java
/** * Write the given {@link GlTF} to the given output stream. The caller * is responsible for closing the stream. * //ww w. ja va 2s . c o m * @param gltf The {@link GlTF} * @param outputStream The output stream * @throws IOException If an IO error occurred */ public void writeGltf(GlTF gltf, OutputStream outputStream) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(Include.NON_NULL); if (indenting) { objectMapper.enable(SerializationFeature.INDENT_OUTPUT); } objectMapper.writeValue(outputStream, gltf); }
From source file:io.cortical.retina.core.Classify.java
/** * Endpoint for creating a {@link CategoryFilter} from text inputs. * /*from w w w . java 2 s. c om*/ * @param filterName the name of the category filter * @param positiveExamples list of strings illustrating positive examples. * @param negativeExamples list of strings illustrating negative examples. * @return {@link CategoryFilter} * @throws ApiException if problem occurs accessing the api */ public CategoryFilter createCategoryFilter(String filterName, List<String> positiveExamples, List<String> negativeExamples) throws ApiException { if (isEmpty(filterName) || positiveExamples == null || positiveExamples.isEmpty()) { throw new IllegalArgumentException(NULL_TEXT_MSG); } Sample sample = makeSample(positiveExamples, negativeExamples); String json = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); json = mapper.writeValueAsString(sample); } catch (JsonProcessingException e) { e.printStackTrace(); } return this.api.createCategoryFilter(filterName, json, retinaName); }
From source file:net.mindengine.galen.reports.json.JsonReportBuilder.java
private ObjectMapper createJsonMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper; }
From source file:uk.ac.soton.itinnovation.sad.service.domain.JsonResponse.java
public JsonResponse(String result, JSONObject response) { this.result = result; ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); JsonFactory factory = mapper.getJsonFactory(); try {/*from w w w. j a v a 2 s . co m*/ JsonParser jp = factory.createJsonParser(response.toString()); this.response = mapper.readTree(jp); } catch (IOException ex) { logger.error("Failed to parse JSONObject", ex); } }
From source file:uk.ac.soton.itinnovation.sad.service.domain.JsonResponse.java
public JsonResponse(String result, JSONArray response) { this.result = result; ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); JsonFactory factory = mapper.getJsonFactory(); try {//from w ww . ja va 2 s . co m JsonParser jp = factory.createJsonParser(response.toString()); this.response = mapper.readTree(jp); } catch (IOException ex) { logger.error("Failed to parse JSONArray", ex); } }