List of usage examples for com.fasterxml.jackson.databind ObjectMapper getSerializationConfig
public SerializationConfig getSerializationConfig()
From source file:com.basistech.AnnotatedDataModelModule.java
/** * Register the Annotated Data Model Jackson module on an {@link com.fasterxml.jackson.databind.ObjectMapper}. * @param mapper the mapper.//from w w w . jav a2 s . c o m * @return the same mapper, for convenience. */ public static ObjectMapper setupObjectMapper(ObjectMapper mapper) { mapper.getSerializationConfig().withSerializationInclusion(JsonInclude.Include.NON_NULL); final AnnotatedDataModelModule module = new AnnotatedDataModelModule(); mapper.registerModule(module); return mapper; }
From source file:org.craftercms.social.migration.util.scripting.ScriptUtils.java
public static String toJson(Object o) throws JsonProcessingException { final ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.getSerializationConfig().without(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.getSerializationConfig().with(SerializationFeature.WRITE_NULL_MAP_VALUES, SerializationFeature.WRITE_EMPTY_JSON_ARRAYS); return mapper.writeValueAsString(o); }
From source file:capital.scalable.restdocs.javadoc.JavadocReaderImpl.java
private static ObjectMapper objectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); return mapper; }
From source file:com.github.camellabs.iot.cloudlet.sdk.RestTemplates.java
public static RestTemplate defaultRestTemplate() { LOG.debug("Creating new default RestTemplate instance."); ObjectMapper objectMapper = new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(FAIL_ON_EMPTY_BEANS, false).setSerializationInclusion(NON_NULL); objectMapper.getSerializationConfig().getDefaultVisibilityChecker().withFieldVisibility(PUBLIC_ONLY); MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter( objectMapper);/*from w w w . java 2 s .c om*/ return new RestTemplate(singletonList(jacksonConverter)); }
From source file:parser.JsonWriter.java
/** * Creates json file for the cloudDSFPlus with all new attributes. * // ww w. j av a2s. com * @param workbook * @throws JsonGenerationException * @throws JsonMappingException * @throws IOException */ private static void writeCloudDSFPlusJson(XSSFWorkbook workbook) throws JsonGenerationException, JsonMappingException, IOException { // instantiate parser for CloudDSFPlus and read excel CloudDSFPlusParser cloudDSFPlusParser = new CloudDSFPlusParser(workbook); CloudDSF cdsf = cloudDSFPlusParser.readExcel(); // check the internal consistency and if successfull serialize data if (cdsf.checkSanity()) { // Helper Method // cdsf.printCloudDSF(); // Jackson objectmapper and settings ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); // Ignore missing getters to serialize all values mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE)); mapper.setSerializationInclusion(Include.NON_NULL); // create json structure JsonNode rootNode = mapper.createObjectNode(); ((ObjectNode) rootNode).putPOJO("cdsfPlus", cdsf); ((ObjectNode) rootNode).putPOJO("links", cdsf.getInfluencingDecisions()); ((ObjectNode) rootNode).putPOJO("outcomeLinks", cdsf.getInfluencingOutcomes()); // Serialize CloudDSFPlus into json file File file = new File("cloudDSFPlus.json"); mapper.writeValue(file, rootNode); System.out.println("Knowledge Base has been successfully verified and exported"); } else { // knowledge base is not valid abort serialization System.out.println("The knowledge base is not valid"); } }
From source file:org.mongojack.internal.util.JacksonAccessor.java
public static SerializerProvider getSerializerProvider(ObjectMapper objectMapper) { DefaultSerializerProvider serializerProvider = (DefaultSerializerProvider) objectMapper .getSerializerProvider();//from w w w. j a v a 2 s .com return serializerProvider.createInstance(objectMapper.getSerializationConfig(), getSerializerFactory(objectMapper)); }
From source file:parser.JsonWriter.java
/** * Generates json file for the CloudDSF avoiding any unnecessary attribute serialization. * /* w ww. j av a 2s.co m*/ * @param workbook * @throws JsonGenerationException * @throws JsonMappingException * @throws IOException */ private static void writeCloudDSFJson(XSSFWorkbook workbook) throws JsonGenerationException, JsonMappingException, IOException { // Instantiate parser to parse file for CloudDSF CloudDSFParser parser = new CloudDSFParser(workbook); // CloudDSF object representing all necessary information CloudDSF cdsf = parser.readExcel(); // Helper Method to check content // cdsf.printCloudDSF(); // Create task tree for legacy visualizations TaskTree taskTree = new TaskTree(); taskTree.setTasks(cdsf.getTasks()); // Jackson objectmapper and settings ObjectMapper mapper = new ObjectMapper(); // Pretty Print mapper.enable(SerializationFeature.INDENT_OUTPUT); // If getter is found values will be serialized avoiding unnecessary attributes mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.DEFAULT) .withGetterVisibility(JsonAutoDetect.Visibility.DEFAULT)); // Ignore fields with null values to avoid serialization of empty lists mapper.setSerializationInclusion(Include.NON_NULL); // Write all relations into one list to conform to legacy implementation cdsf.setInfluencingRelations(); // create json root node and add json objects JsonNode rootNode = mapper.createObjectNode(); ((ObjectNode) rootNode).putPOJO("decisionTree", cdsf); ((ObjectNode) rootNode).putPOJO("taskTree", taskTree); ((ObjectNode) rootNode).putPOJO("linksArray", cdsf.getInfluencingRelations()); // serialize CloudDSF into file File file = new File("cloudDSF.json"); mapper.writeValue(file, rootNode); }
From source file:je.backit.rest.JacksonContextResolver.java
private static ObjectMapper init() { ObjectMapper om = new ObjectMapper(); om.registerModule(new JSR310Module()); om.registerModule(new JooqModule()); om.setSerializationInclusion(JsonInclude.Include.NON_NULL); om.getFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false) .configure(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM, false); om.configure(WRITE_DATES_AS_TIMESTAMPS, false); om.setVisibilityChecker(om.getSerializationConfig().getDefaultVisibilityChecker() .withIsGetterVisibility(NONE).withGetterVisibility(NONE).withFieldVisibility(ANY)); return om;//ww w . j a v a 2s . c o m }
From source file:com.arpnetworking.clusteraggregator.configuration.EmitterConfiguration.java
/** * Create an <code>ObjectMapper</code> for Emitter configuration. * * @param injector The Guice <code>Injector</code> instance. * @return An <code>ObjectMapper</code> for Pipeline configuration. */// w w w . j a v a2 s. co m public static ObjectMapper createObjectMapper(final Injector injector) { final ObjectMapper objectMapper = ObjectMapperFactory.createInstance(); final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector(); objectMapper.setInjectableValues(new GuiceInjectableValues(injector)); objectMapper.setAnnotationIntrospectors( new AnnotationIntrospectorPair(guiceIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector()), new AnnotationIntrospectorPair(guiceIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector())); return objectMapper; }
From source file:com.arpnetworking.metrics.mad.configuration.PipelineConfiguration.java
/** * Create an <code>ObjectMapper</code> for Pipeline configuration. * * @param injector The Guice <code>Injector</code> instance. * @return An <code>ObjectMapper</code> for Pipeline configuration. *//*from w w w .ja va 2 s . c o m*/ public static ObjectMapper createObjectMapper(final Injector injector) { final ObjectMapper objectMapper = ObjectMapperFactory.createInstance(); final SimpleModule module = new SimpleModule("Pipeline"); module.addDeserializer(Statistic.class, new StatisticDeserializer()); objectMapper.registerModules(module); final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector(); objectMapper.setInjectableValues(new GuiceInjectableValues(injector)); objectMapper.setAnnotationIntrospectors( new AnnotationIntrospectorPair(guiceIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector()), new AnnotationIntrospectorPair(guiceIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector())); return objectMapper; }