コード例 #1
0
 @BeforeClass
 public static void createMapper() {
   mapper = new ObjectMapper();
   mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
   mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
   mapper.setTimeZone(TimeZone.getTimeZone("America/Chicago"));
 }
コード例 #2
0
  @Override
  public void startUp() throws Exception {
    // do a DB backup, and keep last 15 copies
    File db = new File(Settings.getInstance().getSettingsFolder(), MOVIE_DB);
    Utils.createBackupFile(db);
    Utils.deleteOldBackupFile(db, 15);

    // configure database
    mvStore =
        new MVStore.Builder()
            .fileName(Settings.getInstance().getSettingsFolder() + File.separatorChar + MOVIE_DB)
            .compressHigh()
            .open();
    mvStore.setAutoCommitDelay(2000); // 2 sec
    mvStore.setRetentionTime(0);
    mvStore.setReuseSpace(true);

    // configure JSON
    objectMapper = new ObjectMapper();
    objectMapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
    objectMapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
    objectMapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
    objectMapper.configure(MapperFeature.AUTO_DETECT_FIELDS, false);
    objectMapper.setTimeZone(TimeZone.getDefault());
    objectMapper.setSerializationInclusion(Include.NON_DEFAULT);

    movieObjectWriter = objectMapper.writerFor(Movie.class);
    movieSetObjectWriter = objectMapper.writerFor(MovieSet.class);

    movieMap = mvStore.openMap("movies");
    movieSetMap = mvStore.openMap("movieSets");

    MovieList.getInstance().loadMoviesFromDatabase(movieMap, objectMapper);
    MovieList.getInstance().loadMovieSetsFromDatabase(movieSetMap, objectMapper);
    MovieList.getInstance().initDataAfterLoading();
    enabled = true;
  }
コード例 #3
0
  /**
   * Configure an existing {@link ObjectMapper} instance with this builder's settings. This can be
   * applied to any number of {@code ObjectMappers}.
   *
   * @param objectMapper the ObjectMapper to configure
   */
  @SuppressWarnings("deprecation")
  public void configure(ObjectMapper objectMapper) {
    Assert.notNull(objectMapper, "ObjectMapper must not be null");

    if (this.findModulesViaServiceLoader) {
      // Jackson 2.2+
      objectMapper.registerModules(ObjectMapper.findModules(this.moduleClassLoader));
    } else if (this.findWellKnownModules) {
      registerWellKnownModulesIfAvailable(objectMapper);
    }

    if (this.modules != null) {
      for (Module module : this.modules) {
        // Using Jackson 2.0+ registerModule method, not Jackson 2.2+ registerModules
        objectMapper.registerModule(module);
      }
    }
    if (this.moduleClasses != null) {
      for (Class<? extends Module> module : this.moduleClasses) {
        objectMapper.registerModule(BeanUtils.instantiate(module));
      }
    }

    if (this.dateFormat != null) {
      objectMapper.setDateFormat(this.dateFormat);
    }
    if (this.locale != null) {
      objectMapper.setLocale(this.locale);
    }
    if (this.timeZone != null) {
      objectMapper.setTimeZone(this.timeZone);
    }

    if (this.annotationIntrospector != null) {
      objectMapper.setAnnotationIntrospector(this.annotationIntrospector);
    }
    if (this.propertyNamingStrategy != null) {
      objectMapper.setPropertyNamingStrategy(this.propertyNamingStrategy);
    }
    if (this.serializationInclusion != null) {
      objectMapper.setSerializationInclusion(this.serializationInclusion);
    }

    if (this.filters != null) {
      // Deprecated as of Jackson 2.6, but just in favor of a fluent variant.
      objectMapper.setFilters(this.filters);
    }

    for (Class<?> target : this.mixIns.keySet()) {
      // Deprecated as of Jackson 2.5, but just in favor of a fluent variant.
      objectMapper.addMixInAnnotations(target, this.mixIns.get(target));
    }

    if (!this.serializers.isEmpty() || !this.deserializers.isEmpty()) {
      SimpleModule module = new SimpleModule();
      addSerializers(module);
      addDeserializers(module);
      objectMapper.registerModule(module);
    }

    customizeDefaultFeatures(objectMapper);
    for (Object feature : this.features.keySet()) {
      configureFeature(objectMapper, feature, this.features.get(feature));
    }

    if (this.handlerInstantiator != null) {
      objectMapper.setHandlerInstantiator(this.handlerInstantiator);
    } else if (this.applicationContext != null) {
      objectMapper.setHandlerInstantiator(
          new SpringHandlerInstantiator(this.applicationContext.getAutowireCapableBeanFactory()));
    }
  }