List of usage examples for com.fasterxml.jackson.datatype.jdk8 Jdk8Module Jdk8Module
Jdk8Module
From source file:org.apache.james.transport.mailets.ICALToJsonAttribute.java
public ICALToJsonAttribute() { this.objectMapper = new ObjectMapper().registerModule(new Jdk8Module()); }
From source file:it.polimi.diceH2020.launcher.model.SimulationsManager.java
public InstanceDataMultiProvider getDecompressedInputData() { if (inputData != null) { return inputData; } else if (getInput() != null) { try {/*from www . j ava2s.c om*/ ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module()) .enable(SerializationFeature.INDENT_OUTPUT); ; return getInput().equals("") || getInput().equals("Error") ? null : mapper.readValue(Compressor.decompress(getInput()), InstanceDataMultiProvider.class); } catch (IOException e) { e.printStackTrace(); return null; } } return inputData; }
From source file:org.zalando.problem.ProblemMixInTest.java
@Test public void shouldSerializeStacktrace() throws JsonProcessingException { final Problem problem = Problem.builder().withType(URI.create("about:blank")).withTitle("Foo") .withStatus(Status.BAD_REQUEST).withCause(Problem.builder().withType(URI.create("about:blank")) .withTitle("Bar").withStatus(Status.BAD_REQUEST).build()) .build();/*from w ww . j a va2 s . c om*/ final ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module()) .registerModule(new ProblemModule().withStacktraces()); final String json = mapper.writeValueAsString(problem); with(json).assertThat("$.stacktrace", is(instanceOf(List.class))).assertThat("$.stacktrace[0]", is(instanceOf(String.class))); }
From source file:it.polimi.diceH2020.plugin.control.FileManager.java
/** * Builds the JSON representation of the current Configuration and * eventually dumps it on a file.//www . j av a2 s .c o m */ public static void generateInputJson() { Configuration conf = Configuration.getCurrent(); // TODO: REMOVE InstanceDataMultiProvider data = InstanceDataMultiProviderGenerator.build(); data.setId(conf.getID()); setMapJobProfile(data, conf); setMapClassParameters(data, conf); if (conf.getIsPrivate()) { data.setMapPublicCloudParameters(null); setPrivateParameters(data); } else { // Set MapVMConfigurations data.setMapVMConfigurations(null); data.setPrivateCloudParameters(null); if (conf.getHasLtc()) { setEtaR(data, conf); } else { data.setMapPublicCloudParameters(null); } } setMachineLearningProfile(data, conf); if (!Configuration.getCurrent().canSend()) { return; } // Generate Json ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new Jdk8Module()); try { mapper.writerWithDefaultPrettyPrinter() .writeValue(new File(Preferences.getSavingDir() + conf.getID() + ".json"), data); } catch (JsonProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.arpnetworking.logback.StenoEncoder.java
StenoEncoder(final JsonFactory jsonFactory, final ObjectMapper objectMapper) { // Initialize object mapper; _objectMapper = objectMapper;// ww w . ja v a 2s. c o m _objectMapper.setAnnotationIntrospector(new StenoAnnotationIntrospector()); final SimpleFilterProvider simpleFilterProvider = new SimpleFilterProvider(); simpleFilterProvider.addFilter(RedactionFilter.REDACTION_FILTER_ID, new RedactionFilter(!DEFAULT_REDACT_NULL)); // Initialize this here based on the above code, if it was initialized at the declaration site then things // could get out of sync _redactEnabled = true; _objectMapper.setFilters(simpleFilterProvider); // Setup writing of Date/DateTime values _objectMapper.registerModule(new JodaModule()); _objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); _objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); _objectMapper.setDateFormat(new ISO8601DateFormat()); // Setup other common modules _objectMapper.registerModule(new AfterburnerModule()); _objectMapper.registerModule(new Jdk7Module()); _objectMapper.registerModule(new Jdk8Module()); _objectMapper.registerModule(new GuavaModule()); // Serialization strategies _listsSerialziationStrategy = new ListsSerialziationStrategy(this, jsonFactory, _objectMapper); _objectAsJsonSerialziationStrategy = new ObjectAsJsonSerialziationStrategy(this, jsonFactory, _objectMapper); _objectSerialziationStrategy = new ObjectSerialziationStrategy(this, jsonFactory, _objectMapper); _mapOfJsonSerialziationStrategy = new MapOfJsonSerialziationStrategy(this, jsonFactory, _objectMapper); _mapSerialziationStrategy = new MapSerialziationStrategy(this, jsonFactory, _objectMapper); _arrayOfJsonSerialziationStrategy = new ArrayOfJsonSerialziationStrategy(this, jsonFactory, _objectMapper); _arraySerialziationStrategy = new ArraySerialziationStrategy(this, jsonFactory, _objectMapper); _standardSerializationStrategy = new StandardSerializationStrategy(this, jsonFactory, _objectMapper); }
From source file:keywhiz.KeywhizService.java
/** * Customizes ObjectMapper for common settings. * * @param objectMapper to be customized/* ww w .j a va 2 s . co m*/ * @return customized input factory */ public static ObjectMapper customizeObjectMapper(ObjectMapper objectMapper) { objectMapper.registerModules(new Jdk8Module()); objectMapper.registerModules(new JavaTimeModule()); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
From source file:io.syndesis.project.converter.DefaultProjectGeneratorTest.java
@Test public void testConvertFromJson() throws Exception { JsonNode json = new ObjectMapper().readTree(this.getClass().getResourceAsStream("test-integration.json")); GenerateProjectRequest request = new GenerateProjectRequest.Builder().integration(new ObjectMapper() .registerModule(new Jdk8Module()).readValue(json.get("data").toString(), Integration.class)) .connectors(connectors).build(); ProjectGeneratorProperties generatorProperties = new ProjectGeneratorProperties(mavenProperties); generatorProperties.getTemplates().setOverridePath(this.basePath); generatorProperties.getTemplates().getAdditionalResources().addAll(this.additionalResources); Path runtimePath = generate(request, generatorProperties); assertFileContents(generatorProperties, runtimePath.resolve("src/main/java/io/syndesis/example/Application.java"), "test-Application.java"); assertFileContents(generatorProperties, runtimePath.resolve("src/main/resources/application.properties"), "test-pull-push-application.properties"); assertFileContents(generatorProperties, runtimePath.resolve("src/main/resources/syndesis.yml"), "test-pull-push-syndesis.yml"); assertFileContents(generatorProperties, runtimePath.resolve("pom.xml"), "test-pull-push-pom.xml"); }
From source file:com.github.helenusdriver.driver.tools.Tool.java
/** * Creates all defined Json schemas based on the provided set of class names * and options and add the schemas to the specified map. For each class found; * the corresponding array element will be nulled. All others are simply * skipped./*from w w w. jav a 2 s . com*/ * * @author paouelle * * @param cnames the set of class names to create Json schemas for * @param suffixes the map of provided suffix values * @param matching whether or not to only create schemas for keyspaces that * matches the specified set of suffixes * @param schemas the map where to record the Json schema for the pojo classes * found * @throws LinkageError if the linkage fails for one of the specified entity * class * @throws ExceptionInInitializerError if the initialization provoked by one * of the specified entity class fails * @throws IOException if an I/O error occurs while generating the Json schemas */ private static void createJsonSchemasFromClasses(String[] cnames, Map<String, String> suffixes, boolean matching, Map<Class<?>, JsonSchema> schemas) throws IOException { next_class: for (int i = 0; i < cnames.length; i++) { try { final Class<?> clazz = Class.forName(cnames[i]); cnames[i] = null; // clear since we found a class final CreateSchema<?> cs = StatementBuilder.createSchema(clazz); // pass all required suffixes for (final Map.Entry<String, String> e : suffixes.entrySet()) { // check if this suffix type is defined final FieldInfo<?> suffix = cs.getClassInfo().getSuffixKeyByType(e.getKey()); if (suffix != null) { // register the suffix value with the corresponding suffix name cs.where(StatementBuilder.eq(suffix.getSuffixKeyName(), e.getValue())); } else if (matching) { // we have one more suffix then defined with this pojo // and we were requested to only do does that match the provided // suffixes so skip the class continue next_class; } } for (final Class<?> c : cs.getObjectClasses()) { System.out.println(Tool.class.getSimpleName() + ": creating Json schema for " + c.getName()); final ObjectMapper m = new ObjectMapper(); final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); m.registerModule(new Jdk8Module()); m.enable(SerializationFeature.INDENT_OUTPUT); m.acceptJsonFormatVisitor(m.constructType(c), visitor); schemas.put(c, visitor.finalSchema()); } } catch (ClassNotFoundException e) { // ignore and continue } } }
From source file:com.github.helenusdriver.driver.tools.Tool.java
/** * Creates all defined Json schemas based on the provided set of package names * and options and add the schemas to the specified map. * * @author paouelle/*from w ww . ja v a 2s . c o m*/ * * @param pkgs the set of packages to create Json schemas for * @param suffixes the map of provided suffix values * @param matching whether or not to only create schemas for keyspaces that * matches the specified set of suffixes * @param schemas the map where to record the Json schema for the pojo classes * found * @throws LinkageError if the linkage fails for one of the specified entity * class * @throws ExceptionInInitializerError if the initialization provoked by one * of the specified entity class fails * @throws IllegalArgumentException if no pojos are found in any of the * specified packages * @throws IOException if an I/O error occurs while generating the Json schemas */ private static void createJsonSchemasFromPackages(String[] pkgs, Map<String, String> suffixes, boolean matching, Map<Class<?>, JsonSchema> schemas) throws IOException { for (final String pkg : pkgs) { if (pkg == null) { continue; } final CreateSchemas cs = (matching ? StatementBuilder.createMatchingSchemas(pkg) : StatementBuilder.createSchemas(pkg)); // pass all suffixes for (final Map.Entry<String, String> e : suffixes.entrySet()) { // register the suffix value with the corresponding suffix type cs.where(StatementBuilder.eq(e.getKey(), e.getValue())); } for (final Class<?> c : cs.getObjectClasses()) { System.out.println(Tool.class.getSimpleName() + ": creating Json schema for " + c.getName()); final ObjectMapper m = new ObjectMapper(); final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); m.registerModule(new Jdk8Module()); m.enable(SerializationFeature.INDENT_OUTPUT); m.acceptJsonFormatVisitor(m.constructType(c), visitor); schemas.put(c, visitor.finalSchema()); } } }