List of usage examples for com.fasterxml.jackson.databind ObjectMapper setSerializationInclusion
public ObjectMapper setSerializationInclusion(JsonInclude.Include incl)
From source file:io.cortical.retina.core.ClassifyTest.java
/** * {@link io.cortical.services.TextRetinaApiImpl#getKeywords(String)} test method. * * @throws io.cortical.services.api.client.ApiException : should never be thrown *///ww w. j a v a2 s.com @Test public void testCreateCategoryFilter() throws ApiException { List<String> pos = Arrays.asList( "Shoe with a lining to help keep your feet dry and comfortable on wet terrain.", "running shoes providing protective cushioning."); List<String> neg = Arrays.asList("The most comfortable socks for your feet.", "6 feet USB cable basic white"); Sample sample = new Sample(); sample.addAllPositive(pos.toArray(new String[pos.size()])); sample.addAllNegative(neg.toArray(new String[neg.size()])); String json = null; try { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); json = mapper.writeValueAsString(sample); } catch (Exception e) { e.printStackTrace(); } when(classifyApi.createCategoryFilter(eq("12"), eq(json), eq("en_associative"))).thenReturn(cf); CategoryFilter result = classify.createCategoryFilter("12", pos, neg); assertTrue(result.getCategoryName().equals("12")); assertTrue(result.getPositions().length == 3); }
From source file:com.redhat.red.offliner.alist.FoloReportArtifactListReader.java
private ObjectMapper newObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, true); mapper.enable(SerializationFeature.INDENT_OUTPUT, SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID); mapper.enable(MapperFeature.AUTO_DETECT_FIELDS); // disable( MapperFeature.AUTO_DETECT_GETTERS ); mapper.disable(SerializationFeature.WRITE_NULL_MAP_VALUES, SerializationFeature.WRITE_EMPTY_JSON_ARRAYS); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.registerModule(new FoloSerializerModule()); return mapper; }
From source file:de.escalon.hypermedia.spring.hydra.HydraMessageConverter.java
/** * Creates new HydraMessageConverter with proxyUnwrapper. * * @param proxyUnwrapper//from www . j ava 2 s.c om * capable of unwrapping proxified Java beans during message conversion. */ public HydraMessageConverter(ProxyUnwrapper proxyUnwrapper, Module... additionalModules) { ObjectMapper objectMapper = new ObjectMapper(); // see https://github.com/json-ld/json-ld.org/issues/76 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.registerModules(additionalModules); objectMapper.registerModule(new JacksonHydraModule(proxyUnwrapper)); this.setObjectMapper(objectMapper); this.setSupportedMediaTypes(Arrays.asList(HypermediaTypes.APPLICATION_JSONLD)); }
From source file:org.o3project.ocnrm.lib.JSONParser.java
public <K> String convertToJson(K target, String seqNo) throws JSONException, JsonProcessingException { logger.info(seqNo + "\t" + "convertToJson() Start"); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); String jsonArray = mapper.writeValueAsString(target); logger.info(seqNo + "\t" + "convertToJson() End"); return jsonArray; }
From source file:org.o3project.ocnrm.lib.JSONParser.java
public LowerNodeInfo lowerNodeInfotoPOJO(JSONObject jsonObj, String seqNo) throws JsonParseException, JsonMappingException, IOException { logger.info(seqNo + "\t" + "lowerNodeInfotoPOJO() Start"); logger.info(seqNo + "\t" + "getParam : " + jsonObj.toString()); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); LowerNodeInfo nodeInfo = mapper.readValue(jsonObj.toString(), LowerNodeInfo.class); logger.info(seqNo + "\t" + "lowerNodeInfotoPOJO() End"); return nodeInfo; }
From source file:com.mugarov.alfapipe.model.programparse.generators.GeneratorCore.java
public void parseOut() { if (this.available != null) { try {/*from w ww . ja va 2 s . c om*/ if (!localFile.exists()) { localFile.createNewFile(); } YAMLFactory factory = new YAMLFactory(); ObjectMapper yamlmap = new ObjectMapper(factory); yamlmap.setSerializationInclusion(JsonInclude.Include.NON_NULL); FileOutputStream fos = new FileOutputStream(localFile); factory.createGenerator(fos).writeObject(this.available); } catch (IOException ex) { Logger.getLogger(GeneratorCore.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.olacabs.fabric.compute.sources.kafka.KafkaSource.java
public void initialize(String instanceId, Properties globalProperties, Properties properties, ProcessingContext processingContext, ComponentMetadata sourceMetadata) throws Exception { final CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(ComponentPropertyReader .readString(properties, globalProperties, "zookeeper", instanceId, sourceMetadata), new RetryForever(1000)); curatorFramework.start();//from w w w . jav a2 s . c om curatorFramework.blockUntilConnected(); curatorFramework.usingNamespace("fabric"); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String startOffsetPickStrategy = ComponentPropertyReader.readString(properties, globalProperties, "startOffsetPickStrategy", instanceId, sourceMetadata, StartOffsetPickStrategy.EARLIEST.toString()); startOffsetPickStrategy = startOffsetPickStrategy.trim(); Preconditions.checkArgument( StartOffsetPickStrategy.EARLIEST.toString().equalsIgnoreCase(startOffsetPickStrategy) || StartOffsetPickStrategy.LATEST.toString().equalsIgnoreCase(startOffsetPickStrategy), String.format("startOffsetPickStrategy must be one of %s or %s", StartOffsetPickStrategy.EARLIEST.toString(), StartOffsetPickStrategy.LATEST.toString())); final int bufferSize = ComponentPropertyReader.readInteger(properties, globalProperties, "buffer_size", instanceId, sourceMetadata, DEFAULT_BUFFER_SIZE); LOGGER.info("Buffer size is set to - {}", bufferSize); balancer = Balancer.builder() .brokers(ComponentPropertyReader.readString(properties, globalProperties, "brokers", instanceId, sourceMetadata)) .curatorFramework(curatorFramework).topologyName(processingContext.getTopologyName()) .topic(ComponentPropertyReader.readString(properties, globalProperties, "topic-name", instanceId, sourceMetadata)) .objectMapper(objectMapper).instanceId(instanceId).bufferSize(bufferSize) .startOffsetPickStrategy(startOffsetPickStrategy).build(); balancer.start(); }
From source file:com.flipkart.bifrost.CommunicationTest.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. java 2 s . c o m BifrostExecutor<Void> executor = BifrostExecutor.<Void>builder(TestAction.class).connection(connection) .objectMapper(mapper).requestQueue("bifrost-send").responseQueue("bifrost-recv").concurrency(10) .executorService(Executors.newFixedThreadPool(10)).build(); BifrostRemoteCallExecutionServer<Void> executionServer = BifrostRemoteCallExecutionServer .<Void>builder(TestAction.class).objectMapper(mapper).connection(connection).concurrency(10) .requestQueue("bifrost-send").build(); executionServer.start(); long startTime = System.currentTimeMillis(); AtomicInteger counter = new AtomicInteger(0); int requestCount = 100; 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(); } } 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:com.mugarov.alfapipe.model.programparse.generators.ExtendedCore.java
public final void parseOut() { if (this.parseableList != null) { try {/* w w w . j ava 2 s . c om*/ if (!localFile.exists()) { localFile.createNewFile(); } YAMLFactory factory = new YAMLFactory(); ObjectMapper yamlmap = new ObjectMapper(factory); yamlmap.setSerializationInclusion(JsonInclude.Include.NON_NULL); FileOutputStream fos = new FileOutputStream(localFile); factory.createGenerator(fos).writeObject(this.parseableList); } catch (IOException ex) { Logger.getLogger(ExtendedCore.class.getName()).log(Level.SEVERE, null, ex); } } else { System.err.println("Error: Not possible to parse out null with " + ExtendedCore.class); } }
From source file:com.rhc.dynamic.pipeline.ObjectMother.java
/** * Helper method to generate json to be used in test * @throws JsonProcessingException//from w w w . j av a 2 s . c o m */ @Test public void shouldGenerateSomeStuff() throws JsonProcessingException { String applicationName = "cool-application-name"; Engagement engagement = buildSingleClusterMultiProjectEngagementNoBuildTool(applicationName); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); String output = mapper.writeValueAsString(engagement); LOGGER.info("\n\n" + output + "\n\n"); }