List of usage examples for com.fasterxml.jackson.datatype.joda JodaModule JodaModule
public JodaModule()
From source file:org.killbill.billing.server.listeners.KillbillPlatformGuiceListener.java
protected void initializeGuice(final ServletContextEvent event) { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JodaModule()); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); guiceModules = ImmutableList.<Module>of(getServletModule(), getJacksonModule(), new JMXModule(KillbillHealthcheck.class, NotificationQueueService.class, PersistentBus.class), new StatsModule(METRICS_SERVLETS_PATHS.get(0), METRICS_SERVLETS_PATHS.get(1), METRICS_SERVLETS_PATHS.get(2), METRICS_SERVLETS_PATHS.get(3), ImmutableList.<Class<? extends HealthCheck>>of(KillbillHealthcheck.class)), getModule(event.getServletContext())); // Start the Guice machinery super.contextInitialized(event); injector = injector(event);/* ww w. j a va 2 s. c om*/ event.getServletContext().setAttribute(Injector.class.getName(), injector); // Already started at this point - we just need the instance for shutdown embeddedDB = injector.getInstance(EmbeddedDB.class); killbillLifecycle = injector.getInstance(Lifecycle.class); killbillBusService = injector.getInstance(BusService.class); }
From source file:com.thinkbiganalytics.nifi.v2.metadata.TriggerFeed.java
@Override protected void init(ProcessorInitializationContext context) { super.init(context); MAPPER.registerModule(new JodaModule()); MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true); MAPPER.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); this.preconditionListener = createPreconditionListener(); }
From source file:eu.trentorise.opendata.jackan.ckan.CkanClient.java
/** * Retrieves the Jackson object mapper. Internally, Object mapper is * initialized at first call.//from www . ja v a 2 s .c o m */ static ObjectMapper getObjectMapper() { if (objectMapper == null) { objectMapper = new ObjectMapper(); objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) // let's be tolerant .configure(MapperFeature.USE_GETTERS_AS_SETTERS, false) // not good for unmodifiable collections, if we will ever use any .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); // When reading dates, Jackson defaults to using GMT for all processing unless specifically told otherwise, see http://wiki.fasterxml.com/JacksonFAQDateHandling // When writing dates, Jackson would add a Z for timezone by CKAN doesn't use it, i.e. "2013-11-11T04:12:11.110868" so we removed it here objectMapper.setDateFormat(new SimpleDateFormat(CKAN_DATE_PATTERN)); // but this only works for Java Dates... // ...so taken solution from here: http://www.lorrin.org/blog/2013/06/28/custom-joda-time-dateformatter-in-jackson/ objectMapper.registerModule(new JodaModule()); objectMapper.registerModule(new GuavaModule()); objectMapper.registerModule(new SimpleModule() { { addSerializer(DateTime.class, new StdSerializer<DateTime>(DateTime.class) { @Override public void serialize(DateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(ckanDateFormatter.print(value)); } }); addDeserializer(DateTime.class, CkanDateDeserializer.forType(DateTime.class)); } }); } return objectMapper; }
From source file:org.bonitasoft.web.designer.config.DesignerConfig.java
@Bean public ObjectMapper objectMapper() { ObjectMapper objectMapper = new ObjectMapper(); //By default all properties without explicit view definition are included in serialization. //To use JsonView we have to change this parameter objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false); //We don't have to serialize null values objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.registerModule(new JodaModule()); objectMapper.registerSubtypes(jacksonSubTypes()); //add Handler to migrate old json objectMapper.addHandler(new JacksonDeserializationProblemHandler()); return objectMapper; }
From source file:com.metamx.rdiclient.RdiClientImplTest.java
@Test public void testMaxQueueBytesFlushing() throws Exception { final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JodaModule()); final Serializer<MmxAuctionSummary> serializer = new JacksonSerializer<>(objectMapper); final RdiClientConfig config = RdiClientConfig.builder().flushCount(500).maxRetries(3).rdiUrl(TARGET_URL) .username("donkey").password("donkeys-love-flowers").postTimeoutMillis(60000).flushBytes(1000) .build();/*from www . jav a2 s .com*/ final RdiClientImpl<MmxAuctionSummary> rdiClient = new RdiClientImpl<>(config, serializer, lifecycle, mockClient); mockClient.setGoHandler(new GoHandler() { @Override protected <Intermediate, Final> ListenableFuture<Final> go(Request<Intermediate, Final> request) throws Exception { Assert.assertEquals(new URL(TARGET_URL), request.getUrl()); Preconditions.checkArgument(request.getHandler() instanceof StatusResponseHandler, "WTF?! Expected StatusResponseHandler."); return Futures.immediateFuture((Final) okResponse()); } }.times(4)); rdiClient.start(); for (MmxAuctionSummary event : Arrays.asList(sampleEventLarge, sampleEventLarge, sampleEventLarge, sampleEventLarge)) { rdiClient.send(event); } rdiClient.flush(); rdiClient.close(); Assert.assertTrue("mockClient succeeded", mockClient.succeeded()); }
From source file:org.efaps.esjp.admin.update.UpdatePack.java
/** * Check revisions.//from w w w . j a v a2 s . c o m * * @param _parameter Parameter as passed by the eFaps API * @return the return * @throws EFapsException on error * @throws InstallationException on error */ public Return execute(final Parameter _parameter) throws EFapsException, InstallationException { final Context context = Context.getThreadContext(); final Context.FileParameter fileItem = context.getFileParameters().get("pack"); final boolean compress = GzipUtils.isCompressedFilename(fileItem.getName()); try (final TarArchiveInputStream tarInput = new TarArchiveInputStream( compress ? new GzipCompressorInputStream(fileItem.getInputStream()) : fileItem.getInputStream());) { File tmpfld = AppConfigHandler.get().getTempFolder(); if (tmpfld == null) { final File temp = File.createTempFile("eFaps", ".tmp"); tmpfld = temp.getParentFile(); temp.delete(); } final File updateFolder = new File(tmpfld, Update.TMPFOLDERNAME); if (!updateFolder.exists()) { updateFolder.mkdirs(); } final File dateFolder = new File(updateFolder, ((Long) new Date().getTime()).toString()); dateFolder.mkdirs(); final Map<String, URL> files = new HashMap<>(); TarArchiveEntry currentEntry = tarInput.getNextTarEntry(); while (currentEntry != null) { final byte[] bytess = new byte[(int) currentEntry.getSize()]; tarInput.read(bytess); final File file = new File(dateFolder.getAbsolutePath() + "/" + currentEntry.getName()); file.getParentFile().mkdirs(); final FileOutputStream output = new FileOutputStream(file); output.write(bytess); output.close(); files.put(currentEntry.getName(), file.toURI().toURL()); currentEntry = tarInput.getNextTarEntry(); } final Map<RevItem, InstallFile> installFiles = new HashMap<>(); final URL json = files.get("revisions.json"); final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JodaModule()); final List<RevItem> items = mapper.readValue(new File(json.toURI()), mapper.getTypeFactory().constructCollectionType(List.class, RevItem.class)); final List<RevItem> allItems = new ArrayList<>(); allItems.addAll(items); installFiles.putAll(getInstallFiles(files, items, CIAdmin.Abstract)); installFiles.putAll(getInstallFiles(files, items, CIAdminUser.Abstract)); installFiles.putAll(getInstallFiles(files, items, CIAdminAccess.AccessSet)); installFiles.putAll(getInstallFiles(files, items, CICommon.DBPropertiesBundle)); final Iterator<RevItem> iter = items.iterator(); int i = 0; while (iter.hasNext()) { final RevItem item = iter.next(); LOG.info("Adding unfound Item {} / {}: {}", i, items.size(), item.getIdentifier()); final InstallFile installFile = new InstallFile().setName(item.getName4InstallFile()) .setURL(item.getURL(files)).setType(item.getFileType().getType()) .setRevision(item.getRevision()).setDate(item.getDate()); installFiles.put(item, installFile); i++; } final List<InstallFile> installFileList = new ArrayList<>(installFiles.values()); Collections.sort(installFileList, new Comparator<InstallFile>() { @Override public int compare(final InstallFile _installFile0, final InstallFile _installFile1) { return _installFile0.getName().compareTo(_installFile1.getName()); } }); final List<InstallFile> dependendFileList = new ArrayList<>(); // check if a object that depends on another object must be added to the update final Map<String, String> depenMap = getDependendMap(); final Set<String> tobeAdded = new HashSet<>(); for (final RevItem item : installFiles.keySet()) { if (depenMap.containsKey(item.getIdentifier())) { tobeAdded.add(depenMap.get(item.getIdentifier())); } } if (!tobeAdded.isEmpty()) { // check if the object to be added is already part ot the list for (final RevItem item : installFiles.keySet()) { final Iterator<String> tobeiter = tobeAdded.iterator(); while (tobeiter.hasNext()) { final String ident = tobeiter.next(); if (item.getIdentifier().equals(ident)) { tobeiter.remove(); } } } } if (!tobeAdded.isEmpty()) { i = 1; // add the objects to the list taht are missing for (final RevItem item : allItems) { if (tobeAdded.contains(item.getIdentifier())) { LOG.info("Adding releated Item {} / {}: {}", i, tobeAdded.size(), item); final InstallFile installFile = new InstallFile().setName(item.getName4InstallFile()) .setURL(item.getURL(files)).setType(item.getFileType().getType()) .setRevision(item.getRevision()).setDate(item.getDate()); dependendFileList.add(installFile); i++; } } } if (!installFileList.isEmpty()) { final Install install = new Install(true); for (final InstallFile installFile : installFileList) { LOG.info("...Adding to Update: '{}' ", installFile.getName()); install.addFile(installFile); } install.updateLatest(null); } if (!dependendFileList.isEmpty()) { LOG.info("Update for related Items"); final Install install = new Install(true); for (final InstallFile installFile : dependendFileList) { LOG.info("...Adding to Update: '{}' ", installFile.getName()); install.addFile(installFile); } install.updateLatest(null); } LOG.info("Terminated update."); } catch (final IOException e) { LOG.error("Catched", e); } catch (final URISyntaxException e) { LOG.error("Catched", e); } return new Return(); }
From source file:org.venice.beachfront.bfapi.BfApiConfig.java
@Bean public ObjectMapper getJacksonObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JodaModule()); return mapper; }
From source file:com.arpnetworking.logback.StenoEncoder.java
StenoEncoder(final JsonFactory jsonFactory, final ObjectMapper objectMapper) { // Initialize object mapper; _objectMapper = objectMapper;//from ww w. ja v a 2s. c om _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:org.killbill.billing.server.listeners.KillbillPlatformGuiceListener.java
protected JaxrsJacksonModule getJacksonModule() { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JodaModule()); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); return new JaxrsJacksonModule(objectMapper); }
From source file:com.metamx.rdiclient.RdiClientImplTest.java
@Test public void testManualFlush() throws Exception { final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JodaModule()); final Serializer<MmxAuctionSummary> serializer = new JacksonSerializer<>(objectMapper); final RdiClientImpl<MmxAuctionSummary> rdiClient = makeRdiClient(serializer, 1000); mockClient.setGoHandler(new GoHandler() { @Override/* ww w. j a va 2s . c o m*/ protected <Intermediate, Final> ListenableFuture<Final> go(Request<Intermediate, Final> request) throws Exception { Assert.assertEquals(new URL(TARGET_URL), request.getUrl()); Preconditions.checkArgument(request.getHandler() instanceof StatusResponseHandler, "WTF?! Expected StatusResponseHandler."); return Futures.immediateFuture((Final) okResponse()); } }.times(1)); rdiClient.start(); for (MmxAuctionSummary event : Arrays.asList(sampleEventLarge, sampleEventLarge, sampleEventLarge, sampleEventLarge)) { rdiClient.send(event); } rdiClient.flush(); rdiClient.close(); Assert.assertTrue("mockClient succeeded", mockClient.succeeded()); }