當前位置: 首頁>>代碼示例>>Java>>正文


Java Module類代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.Module的典型用法代碼示例。如果您正苦於以下問題:Java Module類的具體用法?Java Module怎麽用?Java Module使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Module類屬於com.fasterxml.jackson.databind包,在下文中一共展示了Module類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: configure

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
@Override
protected void configure() {
  Multibinder.newSetBinder(binder(), Module.class, clientBindingAnnotation);
  Multibinder.newSetBinder(binder(), SerializationFeatureFlag.class, clientBindingAnnotation);
  Multibinder.newSetBinder(binder(), DeserializationFeatureFlag.class, clientBindingAnnotation);
  Multibinder.newSetBinder(binder(), JsonGeneratorFeatureFlag.class, clientBindingAnnotation);
  Multibinder.newSetBinder(binder(), JsonParserFeatureFlag.class, clientBindingAnnotation);
  Multibinder.newSetBinder(binder(), MapperFeatureFlag.class, clientBindingAnnotation);

  /**
   * MultibindingsScanner will scan all modules for methods with the annotations @ProvidesIntoMap,
   * @ProvidesIntoSet, and @ProvidesIntoOptional.
   */
  install(MultibindingsScanner.asModule());
  install(AnnotatedJacksonPrivateModule.with(clientBindingAnnotation));
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:17,代碼來源:AnnotatedJacksonModule.java

示例2: configure

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
@Override
protected void configure() {
  requireBinding(ServiceMetadata.class);
  requireBinding(UriInfo.class);

  bind(AvailabilityResource.class).to(AvailabilityResourceImpl.class);
  bind(HealthResource.class).to(HealthResourceImpl.class);
  bind(DependenciesResource.class).to(DependenciesResourceImpl.class);
  bind(DiagnosticResource.class).to(DiagnosticResourceImpl.class);
  bind(VersionResource.class).to(VersionResourceImpl.class);
  bind(HealthChecker.class);

  //This is to provide a default binding for HealthDependency,
  // so that services with no HealthDependency bindings can start
  Multibinder<HealthDependency> healthDependencyModuleBinder = Multibinder.newSetBinder(binder(),
      HealthDependency.class);

  Multibinder<Module> jacksonModuleBinder = Multibinder.newSetBinder(binder(), Module.class);
  jacksonModuleBinder.addBinding().to(Jdk8Module.class);
  jacksonModuleBinder.addBinding().to(JavaTimeModule.class);

  install(MultibindingsScanner.asModule());
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:24,代碼來源:HealthModule.java

示例3: configure

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
@Override
protected void configure() {

  // Empty multibindings for dependencies
  Multibinder<Module> jacksonModuleBinder = Multibinder.newSetBinder(binder(), Module.class);

  Multibinder<SerializationFeatureFlag> serializationFeatureBinder = Multibinder
      .newSetBinder(binder(), SerializationFeatureFlag.class);
  Multibinder<DeserializationFeatureFlag> deserializationFeatureBinder = Multibinder
      .newSetBinder(binder(), DeserializationFeatureFlag.class);
  Multibinder<JsonGeneratorFeatureFlag> jsonGeneratorFeatureBinder = Multibinder
      .newSetBinder(binder(), JsonGeneratorFeatureFlag.class);
  Multibinder<JsonParserFeatureFlag> jsonParserFeatureBinder = Multibinder
      .newSetBinder(binder(), JsonParserFeatureFlag.class);
  Multibinder<MapperFeatureFlag> mapperFeatureBinder = Multibinder
      .newSetBinder(binder(), MapperFeatureFlag.class);

  /**
   * MultibindingsScanner will scan all modules for methods with the annotations @ProvidesIntoMap,
   * @ProvidesIntoSet, and @ProvidesIntoOptional.
   */
  install(MultibindingsScanner.asModule());

  bind(ObjectMapper.class).toProvider(ObjectMapperProvider.class).asEagerSingleton();
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:26,代碼來源:JacksonModule.java

示例4: customDecoder

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
@Test
public void customDecoder() throws Exception {
  JacksonDecoder decoder = new JacksonDecoder(
      Arrays.<Module>asList(
          new SimpleModule().addDeserializer(Zone.class, new ZoneDeserializer())));

  List<Zone> zones = new LinkedList<Zone>();
  zones.add(new Zone("DENOMINATOR.IO."));
  zones.add(new Zone("DENOMINATOR.IO.", "ABCD"));

  Response response = Response.builder()
          .status(200)
          .reason("OK")
          .headers(Collections.<String, Collection<String>>emptyMap())
          .body(zonesJson, UTF_8)
          .build();
  assertEquals(zones, decoder.decode(response, new TypeReference<List<Zone>>() {
  }.getType()));
}
 
開發者ID:wenwu315,項目名稱:XXXX,代碼行數:20,代碼來源:JacksonCodecTest.java

示例5: customEncoder

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
@Test
public void customEncoder() throws Exception {
  JacksonEncoder encoder = new JacksonEncoder(
      Arrays.<Module>asList(new SimpleModule().addSerializer(Zone.class, new ZoneSerializer())));

  List<Zone> zones = new LinkedList<Zone>();
  zones.add(new Zone("denominator.io."));
  zones.add(new Zone("denominator.io.", "abcd"));

  RequestTemplate template = new RequestTemplate();
  encoder.encode(zones, new TypeReference<List<Zone>>() {
  }.getType(), template);

  assertThat(template).hasBody("" //
                               + "[ {\n"
                               + "  \"name\" : \"DENOMINATOR.IO.\"\n"
                               + "}, {\n"
                               + "  \"name\" : \"DENOMINATOR.IO.\",\n"
                               + "  \"id\" : \"ABCD\"\n"
                               + "} ]");
}
 
開發者ID:wenwu315,項目名稱:XXXX,代碼行數:22,代碼來源:JacksonCodecTest.java

示例6: BrpJsonObjectMapper

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
/**
 * Constructor.
 * @param modules Modules
 */
@Inject
public BrpJsonObjectMapper(final Module[] modules) {
    configureerMapper();

    ImmutableMap.<Class<?>, Class<?>>builder()
            .putAll(APPLICATIE_MIXINS)
            .putAll(AUTAUT_MIXINS)
            .putAll(BER_MIXINS)
            .putAll(BEH_MIXINS)
            .putAll(CONV_MIXINS)
            .putAll(KERN_MIXINS)
            .putAll(MIGBLOK_MIXINS)
            .putAll(VERCONV_MIXINS)
            .build()
            .forEach(this::addMixIn);

    // custom serializers / deserializer
    registerModules(modules);
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:24,代碼來源:BrpJsonObjectMapper.java

示例7: jacksonModule

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
@Bean
public Module jacksonModule() {
	SimpleModule module = new SimpleModule();
	module.addSerializer(Foo.class, new JsonSerializer<Foo>() {

		@Override
		public void serialize(Foo value, JsonGenerator jgen,
				SerializerProvider provider)
						throws IOException, JsonProcessingException {
			jgen.writeStartObject();
			jgen.writeStringField("foo", "bar");
			jgen.writeEndObject();
		}
	});
	return module;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:JacksonAutoConfigurationTests.java

示例8: getDeserializersModule

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
private Module getDeserializersModule(GlobalEnvironment environment) {
    return new Module() {
        @Override
        public String getModuleName() {
            return "graphql-spqr-deserializers";
        }

        @Override
        public Version version() {
            return Version.unknownVersion();
        }

        @Override
        public void setupModule(SetupContext setupContext) {
            setupContext.addDeserializers(new ConvertingDeserializers(environment));
        }
    };
}
 
開發者ID:leangen,項目名稱:graphql-spqr,代碼行數:19,代碼來源:JacksonValueMapperFactory.java

示例9: build

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
/**
 * Builds a {@link ConfiguredObjectMapper} using the configuration specified in this builder.
 *
 * @return the constructed object
 */
public ConfiguredObjectMapper build() {
  CacheKey key = new CacheKey(config, modules.build());
  ConfiguredObjectMapper instance = cache.get(key);
  if (instance == null) {
    ObjectMapper mapper =
        ObjectMapperUtil.createStandardObjectMapper(key.apiSerializationConfig);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    for (Module module : key.modulesSet) {
      mapper.registerModule(module);
    }
    instance = new ConfiguredObjectMapper(mapper);

    // Evict all entries if the cache grows beyond a certain size.
    if (maxCacheSize <= cache.size()) {
      cache.clear();
    }

    cache.put(key, instance);
    logger.log(Level.FINE, "Cache miss, created ObjectMapper");
  } else {
    logger.log(Level.FINE, "Cache hit, reusing ObjectMapper");
  }
  return instance;
}
 
開發者ID:cloudendpoints,項目名稱:endpoints-java,代碼行數:31,代碼來源:ConfiguredObjectMapper.java

示例10: shouldUpdateInstanceWithCustomSerialiserAndModules

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
@Test
public void shouldUpdateInstanceWithCustomSerialiserAndModules() throws Exception {
    // Given
    TestCustomJsonSerialiser1.mapper = mock(ObjectMapper.class);
    System.setProperty(JSONSerialiser.JSON_SERIALISER_CLASS_KEY, TestCustomJsonSerialiser1.class.getName());
    TestCustomJsonModules1.modules = Arrays.asList(
            mock(Module.class),
            mock(Module.class)
    );
    TestCustomJsonModules2.modules = Arrays.asList(
            mock(Module.class),
            mock(Module.class)
    );
    System.setProperty(JSONSerialiser.JSON_SERIALISER_MODULES, TestCustomJsonModules1.class.getName() + "," + TestCustomJsonModules2.class.getName());

    // When
    JSONSerialiser.update();

    // Then
    assertEquals(TestCustomJsonSerialiser1.class, JSONSerialiser.getInstance().getClass());
    assertSame(TestCustomJsonSerialiser1.mapper, JSONSerialiser.getMapper());
    verify(TestCustomJsonSerialiser1.mapper).registerModules(TestCustomJsonModules1.modules);
    verify(TestCustomJsonSerialiser1.mapper).registerModules(TestCustomJsonModules2.modules);
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:25,代碼來源:JSONSerialiserTest.java

示例11: shouldUpdateJsonSerialiser

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
@Test
public void shouldUpdateJsonSerialiser() throws StoreException {
    // Given
    final StoreProperties properties = mock(StoreProperties.class);
    given(properties.getJsonSerialiserClass()).willReturn(TestCustomJsonSerialiser1.class.getName());
    given(properties.getJsonSerialiserModules()).willReturn(StorePropertiesTest.TestCustomJsonModules1.class.getName());
    given(properties.getJobExecutorThreadCount()).willReturn(1);

    TestCustomJsonSerialiser1.mapper = mock(ObjectMapper.class);
    System.setProperty(JSONSerialiser.JSON_SERIALISER_CLASS_KEY, TestCustomJsonSerialiser1.class.getName());
    StorePropertiesTest.TestCustomJsonModules1.modules = Arrays.asList(
            mock(Module.class),
            mock(Module.class)
    );

    final Store store = new StoreImpl();
    final Schema schema = new Schema();

    // When
    store.initialise("graphId", schema, properties);

    // Then
    assertEquals(TestCustomJsonSerialiser1.class, JSONSerialiser.getInstance().getClass());
    assertSame(TestCustomJsonSerialiser1.mapper, JSONSerialiser.getMapper());
    verify(TestCustomJsonSerialiser1.mapper).registerModules(StorePropertiesTest.TestCustomJsonModules1.modules);
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:27,代碼來源:StoreTest.java

示例12: createObjectMapper

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
public static ObjectMapper createObjectMapper(ApplicationContext applicationContext){
		ObjectMapper mapper = JsonMapper.ignoreNull().getObjectMapper();
//		h4m.disable(Hibernate4Module.Feature.FORCE_LAZY_LOADING);
		String clsName = "com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module";
		if(ClassUtils.isPresent(clsName, ClassUtils.getDefaultClassLoader())){
			Object h4m = ReflectUtils.newInstance(clsName);
			
			Class<?> featureCls = ReflectUtils.loadClass(clsName+"$Feature");
			Object field = ReflectUtils.getStaticFieldValue(featureCls, "SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS");
			ReflectUtils.invokeMethod("enable", h4m, field);

			field = ReflectUtils.getStaticFieldValue(featureCls, "FORCE_LAZY_LOADING");
			ReflectUtils.invokeMethod("disable", h4m, field);
			mapper.registerModule((Module)h4m);
		}
		List<Module> modules = SpringUtils.getBeans(applicationContext, Module.class);
		if(LangUtils.isNotEmpty(modules))
			mapper.registerModules(modules);
		return mapper;
	}
 
開發者ID:wayshall,項目名稱:onetwo,代碼行數:21,代碼來源:BootWebUtils.java

示例13: customJacksonModuleToSerializeInstantAsIso8601

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
@Bean
public Module customJacksonModuleToSerializeInstantAsIso8601() {
    SimpleModule module = new SimpleModule();
    module.addDeserializer(Instant.class, new JsonDeserializer<Instant>() {
        @Override
        public Instant deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return Instant.from(DateTimeFormatter.ISO_INSTANT.parse(jsonParser.getText()));
        }
    });
    module.addSerializer(Instant.class, new JsonSerializer<Instant>() {
        @Override
        public void serialize(Instant instant, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
            jsonGenerator.writeString(DateTimeFormatter.ISO_INSTANT.format(instant));
        }
    });
    return module;
}
 
開發者ID:sakaiproject,項目名稱:sakai,代碼行數:18,代碼來源:AppConfig.java

示例14: Buffer

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
protected Buffer(final Config config)
{
    this.config = config;
    if (config.getFileBackupDir() != null) {
        fileBackup = new FileBackup(new File(config.getFileBackupDir()), this, config.getFileBackupPrefix());
    }
    else {
        fileBackup = null;
    }

    objectMapper = new ObjectMapper(new MessagePackFactory());
    List<Module> jacksonModules = config.getJacksonModules();
    for (Module module : jacksonModules) {
        objectMapper.registerModule(module);
    }
}
 
開發者ID:komamitsu,項目名稱:fluency,代碼行數:17,代碼來源:Buffer.java

示例15: springDataPageModule

import com.fasterxml.jackson.databind.Module; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
@Bean
public Module springDataPageModule() {
    return new SimpleModule().addSerializer(Page.class, new JsonSerializer<Page>() {
        @Override
        public void serialize(Page value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
            gen.writeStartObject();
            gen.writeNumberField("totalElements", value.getTotalElements());
            gen.writeNumberField("totalPages", value.getTotalPages());
            gen.writeNumberField("numberOfElements", value.getNumberOfElements());
            gen.writeObjectField("sort", value.getSort());
            gen.writeBooleanField("last", value.isLast());
            gen.writeBooleanField("first", value.isFirst());
            gen.writeFieldName("content");
            serializers.defaultSerializeValue(value.getContent(), gen);
            gen.writeEndObject();
        }
    });
}
 
開發者ID:Dica-Developer,項目名稱:weplantaforest,代碼行數:20,代碼來源:JsonSerializerConfig.java


注:本文中的com.fasterxml.jackson.databind.Module類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。