List of usage examples for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion
public ObjectMapper setSerializationInclusion(JsonInclude.Include incl)
From source file:org.redisson.codec.JsonJacksonCodec.java
private void createObjectMapper(ObjectMapper objectMapper) { objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true); objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); }
From source file:uk.co.flax.biosolr.ontology.documents.storage.elasticsearch.ESStorageEngine.java
/** * Get an object mapper for serializing the product data. * @return the object mapper.// w ww. ja v a 2s. c o m */ private ObjectMapper getSerializationMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); return mapper; }
From source file:com.flipkart.bifrost.ListenTest.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();/*w ww .j a va2 s. co m*/ BifrostExecutor<Void> executor = BifrostExecutor.<Void>builder(TestAction.class).connection(connection) .objectMapper(mapper).requestQueue("bifrost-send").responseQueue("bifrost-recv").concurrency(20) .executorService(Executors.newFixedThreadPool(20)).build(); BifrostRemoteCallExecutionServer<Void> executionServer = BifrostRemoteCallExecutionServer .<Void>builder(TestAction.class).objectMapper(mapper).connection(connection).concurrency(20) .requestQueue("bifrost-send").build(); executionServer.start(); long startTime = System.currentTimeMillis(); AtomicInteger counter = new AtomicInteger(0); int requestCount = 1000000; CompletionService<Void> ecs = new ExecutorCompletionService<>(Executors.newFixedThreadPool(50)); List<Future<Void>> futures = Lists.newArrayListWithCapacity(requestCount); for (int i = 0; i < requestCount; i++) { futures.add(ecs.submit(new ServiceCaller(executor, counter))); } for (int i = 0; i < requestCount; i++) { try { ecs.take().get(); } catch (ExecutionException e) { e.printStackTrace(); } } while (counter.get() != requestCount) ; System.out.println( String.format("Completed: %d in %d ms", counter.get(), (System.currentTimeMillis() - startTime))); executor.shutdown(); executionServer.stop(); connection.stop(); Assert.assertEquals(requestCount, counter.get()); }
From source file:org.al.swagger.v2.AbstractSpecCollector.java
public void collectAndOutputSpec(OutputStream stream, String host, String description, String version, String title, String contactEmail, String contactName, String contactURL, String basePath, List<String> transportSchemas) throws IOException { SwaggerSpecV2 swager = new SwaggerSpecV2(); swager.setSwagger("2.0"); Info info = new Info(); info.setDescription(description);/*from w ww .j a v a 2 s .c o m*/ info.setVersion(version); info.setTitle(title); //todo: term of use missing Contact contact = new Contact(); contact.setEmail(contactEmail); contact.setName(contactName); contact.setUrl(contactURL); info.setContact(contact); License license = new License(); license.setName("Copyright 2015 Integ Enterprise Consulting Inc."); license.setUrl("http://www.integconsulting.com"); info.setLicense(license); swager.setInfo(info); swager.setHost(host); swager.setBasePath(basePath); swager.setTags(generateTags()); swager.setSchemes(transportSchemas); swager.setConsumes(Arrays.asList(jsonFormat)); swager.setProduces(Arrays.asList(jsonFormat)); swager.setPaths(generatePaths()); swager.setDefinitions(generateDefinitions()); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) .configure(SerializationFeature.INDENT_OUTPUT, true).writeValue(stream, swager); }
From source file:springfox.test.contract.swagger.listeners.ObjectMapperEventListener.java
@Override public void onApplicationEvent(ObjectMapperConfigured event) { ObjectMapper objectMapper = event.getObjectMapper(); objectMapper.configure(com.fasterxml.jackson.databind.SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true); objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS); }
From source file:com.marvinformatics.hibernate.json.JsonUserType.java
String convertObjectToJson(Object object) { try {/*from www.ja v a2s . c o m*/ ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper.writeValueAsString(object); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:net.solarnetwork.node.dao.jdbc.test.JdbcGeneralNodeDatumDaoTest.java
@Before public void setup() { DatabaseSetup setup = new DatabaseSetup(); setup.setDataSource(dataSource);// www . j a v a 2 s .c om setup.init(); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); dao = new JdbcGeneralNodeDatumDao(); dao.setDataSource(dataSource); dao.setObjectMapper(mapper); dao.init(); }
From source file:net.solarnetwork.node.dao.jdbc.test.JdbcGeneralLocationDatumDaoTest.java
@Before public void setup() { DatabaseSetup setup = new DatabaseSetup(); setup.setDataSource(dataSource);//from ww w . java2s. c o m setup.init(); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); dao = new JdbcGeneralLocationDatumDao(); dao.setDataSource(dataSource); dao.setObjectMapper(mapper); dao.init(); }
From source file:nl.pinniq.web.config.WebMvcConfiguration.java
@Bean public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); //objectMapper.registerModule(new JSR310Module()); MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); converter.setObjectMapper(objectMapper); return converter; }
From source file:com.netflix.config.DynamicContextualPropertyTest.java
@Test public void testPropertyChange() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); List<Value<Integer>> values = Lists.newArrayList(); Value<Integer> value = new Value<Integer>(); Map<String, Collection<String>> dimension = Maps.newHashMap(); dimension.put("d1", Lists.newArrayList("v1", "v2")); value.setDimensions(dimension);//from w w w . j a va 2 s . co m value.setValue(5); values.add(value); Value<Integer> value2 = new Value<Integer>(); Map<String, Collection<String>> dimension2 = Maps.newHashMap(); dimension2.put("d1", Lists.newArrayList("v3")); dimension2.put("d2", Lists.newArrayList("x1")); value2.setDimensions(dimension2); value2.setValue(10); values.add(value2); value = new Value<Integer>(); value.setValue(2); values.add(value); String json = mapper.writeValueAsString(values); System.out.println("serialized json: " + json); ConfigurationManager.getConfigInstance().setProperty("d1", "v1"); ConfigurationManager.getConfigInstance().setProperty("contextualProp", json); DynamicContextualProperty<Integer> prop = new DynamicContextualProperty<Integer>("contextualProp", 0); // d1=v1 assertEquals(5, prop.getValue().intValue()); // d1=v2 ConfigurationManager.getConfigInstance().setProperty("d1", "v2"); assertEquals(5, prop.getValue().intValue()); // d1=v3 ConfigurationManager.getConfigInstance().setProperty("d1", "v3"); assertEquals(2, prop.getValue().intValue()); // d1=v3, d2 = x1 ConfigurationManager.getConfigInstance().setProperty("d2", "x1"); assertEquals(10, prop.getValue().intValue()); // d1=v1, d2 = x1 ConfigurationManager.getConfigInstance().setProperty("d1", "v1"); assertEquals(5, prop.getValue().intValue()); values.remove(0); json = mapper.writeValueAsString(values); ConfigurationManager.getConfigInstance().setProperty("contextualProp", json); assertEquals(2, prop.getValue().intValue()); ConfigurationManager.getConfigInstance().clearProperty("contextualProp"); assertEquals(0, prop.getValue().intValue()); }