List of usage examples for com.fasterxml.jackson.databind ObjectMapper disable
public ObjectMapper disable(SerializationFeature f)
From source file:org.apache.taverna.robundle.manifest.Manifest.java
/** * Write as an RO Bundle JSON-LD manifest * /*from w ww . j a v a 2 s. co m*/ * @return The path of the written manifest (e.g. ".ro/manifest.json") * @throws IOException */ public Path writeAsJsonLD() throws IOException { Path jsonld = bundle.getFileSystem().getPath(RO, MANIFEST_JSON); createDirectories(jsonld.getParent()); // Files.createFile(jsonld); if (!getManifest().contains(jsonld)) getManifest().add(0, jsonld); ObjectMapper om = new ObjectMapper(); om.addMixInAnnotations(Path.class, PathMixin.class); om.addMixInAnnotations(FileTime.class, FileTimeMixin.class); om.enable(INDENT_OUTPUT); om.disable(WRITE_EMPTY_JSON_ARRAYS); om.disable(FAIL_ON_EMPTY_BEANS); om.disable(WRITE_NULL_MAP_VALUES); om.setSerializationInclusion(Include.NON_NULL); try (Writer w = newBufferedWriter(jsonld, Charset.forName("UTF-8"), WRITE, TRUNCATE_EXISTING, CREATE)) { om.writeValue(w, this); } return jsonld; }
From source file:com.proofpoint.json.JsonCodecFactory.java
private ObjectMapper createObjectMapper() { ObjectMapper objectMapper = null; // Work around for http://code.google.com/p/google-guice/issues/detail?id=627 RuntimeException lastException = null; for (int i = 0; objectMapper == null && i < 10; i++) { try {//from www. j a va 2 s.com objectMapper = objectMapperProvider.get(); } catch (RuntimeException e) { lastException = e; } } if (objectMapper == null) { throw lastException; } if (prettyPrint) { objectMapper.enable(INDENT_OUTPUT); } else { objectMapper.disable(INDENT_OUTPUT); } return objectMapper; }
From source file:org.agatom.springatom.boot.init.rest.SARepositoryRestMvcConfiguration.java
/** {@inheritDoc} */ @Override//from w w w. j a v a2 s. c o m protected void configureJacksonObjectMapper(final ObjectMapper objectMapper) { super.configureJacksonObjectMapper(objectMapper); for (final Boolean key : this.enableDisableFeatures.keySet()) { final List<Object> objects = this.enableDisableFeatures.get(key); for (final Object obj : objects) { if (key) { if (ClassUtils.isAssignableValue(SerializationFeature.class, obj)) { objectMapper.enable((SerializationFeature) obj); } else { objectMapper.enable((DeserializationFeature) obj); } } else { if (ClassUtils.isAssignableValue(SerializationFeature.class, obj)) { objectMapper.disable((SerializationFeature) obj); } else { objectMapper.disable((DeserializationFeature) obj); } } } } }
From source file:com.netflix.dyno.queues.redis.RedisDynoQueue.java
public RedisDynoQueue(String redisKeyPrefix, String queueName, Set<String> allShards, String shardName, ExecutorService dynoCallExecutor) { this.redisKeyPrefix = redisKeyPrefix; this.queueName = queueName; this.allShards = allShards.stream().collect(Collectors.toList()); this.shardName = shardName; this.messageStoreKey = redisKeyPrefix + ".MESSAGE." + queueName; this.myQueueShard = getQueueShardKey(queueName, shardName); ObjectMapper om = new ObjectMapper(); om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); om.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false); om.setSerializationInclusion(Include.NON_NULL); om.setSerializationInclusion(Include.NON_EMPTY); om.disable(SerializationFeature.INDENT_OUTPUT); this.om = om; this.monitor = new QueueMonitor(queueName, shardName); this.prefetchedIds = new LinkedBlockingQueue<>(); this.executorService = dynoCallExecutor; Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> processUnacks(), unackScheduleInMS, unackScheduleInMS, TimeUnit.MILLISECONDS); Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> prefetchIds(), 0, 10, TimeUnit.MILLISECONDS); logger.info(RedisDynoQueue.class.getName() + " is ready to serve " + queueName); }
From source file:org.apache.nifi.toolkit.s2s.SiteToSiteCliMain.java
/** * Prints the usage to System.out/*from w w w . ja va 2 s. co m*/ * * @param errorMessage optional error message * @param options the options object to print usage for */ public static void printUsage(String errorMessage, Options options) { if (errorMessage != null) { System.out.println(errorMessage); System.out.println(); System.out.println(); } ObjectMapper objectMapper = new ObjectMapper(); objectMapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); System.out.println( "s2s is a command line tool that can either read a list of DataPackets from stdin to send over site-to-site or write the received DataPackets to stdout"); System.out.println(); System.out.println( "The s2s cli input/output format is a JSON list of DataPackets. They can have the following formats:"); try { System.out.println(); objectMapper.writeValue(System.out, Arrays.asList( new DataPacketDto("hello nifi".getBytes(StandardCharsets.UTF_8)).putAttribute("key", "value"))); System.out.println(); System.out.println( "Where data is the base64 encoded value of the FlowFile content (always used for received data) or"); System.out.println(); objectMapper.writeValue(System.out, Arrays.asList(new DataPacketDto(new HashMap<>(), new File("EXAMPLE").getAbsolutePath()) .putAttribute("key", "value"))); System.out.println(); System.out.println("Where dataFile is a file to read the FlowFile content from"); System.out.println(); System.out.println(); System.out.println( "Example usage to send a FlowFile with the contents of \"hey nifi\" to a local unsecured NiFi over http with an input port named input:"); System.out.print("echo '"); DataPacketDto dataPacketDto = new DataPacketDto("hey nifi".getBytes(StandardCharsets.UTF_8)); dataPacketDto.setAttributes(null); objectMapper.writeValue(System.out, Arrays.asList(dataPacketDto)); System.out.println("' | bin/s2s.sh -n input -p http"); System.out.println(); } catch (IOException e) { e.printStackTrace(); } HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setWidth(160); helpFormatter.printHelp("s2s", options); System.out.flush(); }
From source file:org.openecomp.sdnc.sli.aai.AAIService.java
public static ObjectMapper getObjectMapper() { ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(introspector, secondary)); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setSerializationInclusion(Include.NON_NULL); return mapper; }
From source file:org.pentaho.metaverse.impl.model.ExecutionProfileUtil.java
public static void outputExecutionProfile(OutputStream outputStream, IExecutionProfile executionProfile) throws IOException { PrintStream out = null;//from w ww .ja v a2s .c om try { if (outputStream instanceof PrintStream) { out = (PrintStream) outputStream; } else { out = new PrintStream(outputStream); } ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.enable(SerializationFeature.WRAP_EXCEPTIONS); try { out.println(mapper.writeValueAsString(executionProfile)); } catch (JsonProcessingException jpe) { throw new IOException(jpe); } } finally { IOUtils.closeQuietly(out); } }
From source file:org.verdictdb.core.scrambling.ScrambleMeta.java
public static ScrambleMeta fromJsonString(String jsonString) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); try {/*from w ww .j a v a2 s . c o m*/ ScrambleMeta meta = objectMapper.readValue(jsonString, ScrambleMeta.class); return meta; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:org.wisdom.content.jackson.JacksonSingleton.java
private void applyMapperConfiguration(ObjectMapper mapper, XmlMapper xml) { Configuration conf = null;//from ww w.j a v a 2s .c o m // Check for test. if (configuration != null) { conf = configuration.getConfiguration("jackson"); } if (conf == null) { LOGGER.info("Using default (Wisdom) configuration of Jackson"); LOGGER.info("FAIL_ON_UNKNOWN_PROPERTIES is disabled"); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); xml.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); } else { LOGGER.info("Applying custom configuration on Jackson mapper"); Set<String> keys = conf.asMap().keySet(); for (String key : keys) { setFeature(mapper, xml, key, conf.getBoolean(key)); } } }