com.fasterxml.jackson.databind.Module源码实例Demo

类com.fasterxml.jackson.databind.Module源码实例Demo

下面列出了com.fasterxml.jackson.databind.Module 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: onetwo   文件: BootWebUtils.java
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;
	}
 
源代码2 项目: graphql-spqr   文件: JacksonValueMapperFactory.java
private Module getDeserializersModule(GlobalEnvironment environment, ObjectMapper mapper) {
    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, mapper));
        }
    };
}
 
源代码3 项目: endpoints-java   文件: ConfiguredObjectMapper.java
/**
 * 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.atFine().log("Cache miss, created ObjectMapper");
  } else {
    logger.atFine().log("Cache hit, reusing ObjectMapper");
  }
  return instance;
}
 
源代码4 项目: Eagle   文件: JsonSerDeserUtils.java
public static <T> T deserialize(String value, Class<T> cls, List<Module> modules) throws Exception{
	ObjectMapper mapper = new ObjectMapper();
	if (modules != null) { 
		mapper.registerModules(modules);
	}
	return mapper.readValue(value, cls);	
}
 
源代码5 项目: eagle   文件: KafkaConsumerOffsetFetcher.java
public KafkaConsumerOffsetFetcher(ZKConfig config, String... parameters) {
    try {
        this.curator = CuratorFrameworkFactory.newClient(config.zkQuorum, config.zkSessionTimeoutMs, 15000,
            new RetryNTimes(config.zkRetryTimes, config.zkRetryInterval));
        curator.start();
        this.zkRoot = config.zkRoot;
        mapper = new ObjectMapper();
        Module module = new SimpleModule("offset").registerSubtypes(new NamedType(KafkaConsumerOffset.class));
        mapper.registerModule(module);
        zkPathToPartition = String.format(config.zkRoot, parameters);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
源代码6 项目: heroic   文件: FilterRegistry.java
public Module module(final QueryParser parser) {
    final SimpleModule m = new SimpleModule("filter");

    for (final Map.Entry<Class<? extends Filter>, JsonSerializer<Filter>> e : this
        .serializers.entrySet()) {
        m.addSerializer(e.getKey(), e.getValue());
    }

    final FilterJsonDeserializer deserializer =
        new FilterJsonDeserializer(ImmutableMap.copyOf(deserializers), typeNameMapping, parser);
    m.addDeserializer(Filter.class, deserializer);
    return m;
}
 
源代码7 项目: minnal   文件: DefaultJsonSerializerTest.java
@Test
public void shouldRegisterMultipleModules() {
	ObjectMapper mapper = spy(new ObjectMapper());
	serializer = new DefaultJsonSerializer(mapper) {
		@Override
		protected void registerModules(ObjectMapper mapper) {
			mapper.registerModule(new SimpleModule());
			mapper.registerModule(new SimpleModule());
			mapper.registerModule(new SimpleModule());
		}
	};
	verify(mapper, times(3)).registerModule(any(Module.class));
}
 
源代码8 项目: jackson-modules-base   文件: ObjectMapperModule.java
public ObjectMapperProvider(List<Key<? extends Module>> modulesToInject,
    List<Module> modulesToAdd, ObjectMapper mapper)
{
  this.modulesToInject = modulesToInject;
  this.modulesToAdd = modulesToAdd;
  objectMapper = mapper;
  this.providedModules = new ArrayList<Provider<? extends Module>>();
}
 
源代码9 项目: Eagle   文件: JsonSerDeserUtils.java
public static <T> String serialize(T o, List<Module> modules) throws Exception {
	ObjectMapper mapper = new ObjectMapper();
	if (modules != null) { 
		mapper.registerModules(modules);
	}
	return mapper.writeValueAsString(o);
}
 
源代码10 项目: immutables   文件: JacksonCodecs.java
/**
 * Create module from existing registry
 */
private static Module module(final CodecRegistry registry) {
  Objects.requireNonNull(registry, "registry");
  return new Module() {
    @Override
    public String getModuleName() {
      return JacksonCodecs.class.getSimpleName();
    }

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

    @Override
    public void setupModule(SetupContext context) {
      context.addSerializers(serializers(registry));
      context.addDeserializers(deserializers(registry));
    }

    @Override
    public Object getTypeId() {
      // return null so multiple modules can be registered
      // with same ObjectMapper instance
      return null;
    }
  };
}
 
源代码11 项目: ob1k   文件: JsonRequestMarshaller.java
public JsonRequestMarshaller(Module... module) {
  factory = new JsonFactory();
  mapper = new ObjectMapper(factory);
  mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  for (Module m : module) {
    mapper.registerModule(m);
  }
  marshallingStrategy = new JacksonMarshallingStrategy(mapper);
}
 
源代码12 项目: camunda-bpm-reactor   文件: JsonCodec.java
/**
 * Creates a new {@code JsonCodec} that will create instances of {@code inputType}  when
 * decoding. The {@code customModule} will be registered with the underlying {@link
 * ObjectMapper}.
 *
 * @param inputType    The type to create when decoding.
 * @param customModule The module to register with the underlying ObjectMapper
 * @param delimiter    A nullable delimiting byte for batch decoding
 */
@SuppressWarnings("unchecked")
public JsonCodec(Class<IN> inputType, Module customModule, Byte delimiter) {
  super(delimiter);
  requireNonNull(inputType, "inputType must not be null");
  this.inputType = inputType;

  this.mapper = new ObjectMapper();
  if (null != customModule) {
    this.mapper.registerModule(customModule);
  }
}
 
源代码13 项目: carbon-apimgt   文件: ObjectMapperFactory.java
private static ObjectMapper create(JsonFactory jsonFactory, boolean includePathDeserializer,
        boolean includeResponseDeserializer) {
    ObjectMapper mapper = jsonFactory == null ? new ObjectMapper() : new ObjectMapper(jsonFactory);

    Module deserializerModule = new DeserializationModule(includePathDeserializer, includeResponseDeserializer);
    mapper.registerModule(deserializerModule);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    return mapper;
}
 
源代码14 项目: james-project   文件: JsonExtractor.java
public JsonExtractor(Class<RequestT> type, List<Module> modules) {
    this.objectMapper = new ObjectMapper()
        .registerModule(new Jdk8Module())
        .registerModule(new GuavaModule())
        .registerModules(modules);
    this.type = type;
}
 
源代码15 项目: graphql-spqr   文件: JacksonValueMapperFactory.java
private Module getAnnotationIntrospectorModule(Map<Class, Class> unambiguousTypes, Map<Type, List<NamedType>> ambiguousTypes, MessageBundle messageBundle) {
    SimpleModule module = new SimpleModule("graphql-spqr-annotation-introspector") {
        @Override
        public void setupModule(SetupContext context) {
            super.setupModule(context);
            context.insertAnnotationIntrospector(new AnnotationIntrospector(ambiguousTypes, messageBundle));
        }
    };
    unambiguousTypes.forEach(module::addAbstractTypeMapping);
    return module;
}
 
@Test
public void testBuildWithModules_manyWithEmpty() {
  ConfiguredObjectMapper result1 =
      builder.addRegisteredModules(ImmutableList.<Module>of()).build();
  assertEquals(1, cache.size());
  ConfiguredObjectMapper result2 =
      builder.addRegisteredModules(ImmutableList.<Module>of()).build();
  assertEquals(1, cache.size());
  assertSame(result1, result2);
}
 
源代码17 项目: james-project   文件: JsonTransformer.java
private JsonTransformer(Collection<Module> modules) {
    objectMapper = new ObjectMapper()
        .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
        .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
        .registerModule(new Jdk8Module())
        .registerModule(new JavaTimeModule())
        .registerModule(new GuavaModule())
        .registerModules(modules);
}
 
源代码18 项目: msf4j   文件: MSF4JJacksonDecoder.java
public MSF4JJacksonDecoder() {
    this(Collections.<Module>emptyList());
}
 
源代码19 项目: consensusj   文件: BitcoinConfig.java
@Bean
public Module bitcoinJMapper(NetworkParameters params) {
    return new RpcServerModule(params);
}
 
源代码20 项目: micro-server   文件: JacksonPlugin.java
@Override
public Set<Module> jacksonModules() {
    return SetX.of();
}
 
@Bean
public Module schemaSerializationModule() {
  return new SchemaSerializationModule();
}
 
源代码22 项目: feign   文件: JacksonIteratorDecoder.java
public static JacksonIteratorDecoder create(Iterable<Module> modules) {
  return new JacksonIteratorDecoder(new ObjectMapper()
      .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
      .registerModules(modules));
}
 
源代码23 项目: heroic   文件: HeroicMappers.java
public static Module commonSerializers() {
    final SimpleModule serializers = new SimpleModule("common");
    serializers.addDeserializer(Duration.class, new DurationSerialization.Deserializer());
    serializers.addDeserializer(Groups.class, new GroupsSerialization.Deserializer());
    return serializers;
}
 
@Bean
public Module Jackson2HalModule() {
	return new Jackson2HalModule();
}
 
源代码25 项目: moserp   文件: RestConfiguration.java
@Bean
public Module jsr310Module() {
    return new JavaTimeModule();
}
 
源代码26 项目: jackson-modules-base   文件: ObjectMapperModule.java
public ObjectMapperModule registerModule(Key<? extends Module> key)
{
  modulesToInject.add(key);
  return this;
}
 
源代码27 项目: Eagle   文件: PolicyManager.java
public List<Module> getPolicyModules(String policyType){
	return policyModules.get(policyType);
}
 
public final TypeSpec generateJacksonModule() {
    TypeSpec.Builder type = TypeSpec.classBuilder("YamlModule");
    type.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
    type.superclass(Module.class);
    type.addMethod(
        MethodSpec.methodBuilder("getModuleName")
            .addModifiers(Modifier.PUBLIC)
            .addAnnotation(Override.class)
            .returns(String.class)
            .addCode(CodeBlock.builder().addStatement("return $S", "camel-yaml").build())
            .build()
    );
    type.addMethod(
        MethodSpec.methodBuilder("version")
            .addModifiers(Modifier.PUBLIC)
            .addAnnotation(Override.class)
            .returns(Version.class)
            .addCode(CodeBlock.builder().addStatement("return $L", "Version.unknownVersion()").build())
            .build()
    );

    MethodSpec.Builder mb = MethodSpec.methodBuilder("setupModule")
        .addModifiers(Modifier.PUBLIC)
        .addParameter(Module.SetupContext.class, "context");

    definitions(EXPRESSION_DEFINITION_CLASS).forEach(
        (k, v) -> mb.addStatement("context.registerSubtypes(new com.fasterxml.jackson.databind.jsontype.NamedType($L.class, $S))", v.getName(), k)
    );
    definitions(DATAFORMAT_DEFINITION_CLASS).forEach(
        (k, v) -> mb.addStatement("context.registerSubtypes(new com.fasterxml.jackson.databind.jsontype.NamedType($L.class, $S))", v.getName(), k)
    );
    definitions(LOAD_BALANCE_DEFINITION_CLASS).forEach(
        (k, v) -> mb.addStatement("context.registerSubtypes(new com.fasterxml.jackson.databind.jsontype.NamedType($L.class, $S))", v.getName(), k)
    );

    annotated(YAML_MIXIN_ANNOTATION).forEach(i -> {
        final AnnotationInstance annotation = i.classAnnotation(YAML_MIXIN_ANNOTATION);
        final AnnotationValue targets = annotation.value("value");

        String name = i.toString();
        if (i.nestingType() == ClassInfo.NestingType.INNER) {
            name = i.enclosingClass().toString() + "." + i.simpleName();
        }

        if (targets != null) {
            for (String target: targets.asStringArray()) {
                mb.addStatement("context.setMixInAnnotations($L.class, $L.class);", target, name);
            }
        }
    });


    type.addMethod(mb.build());

    return type.build();
}
 
@Bean
@ConditionalOnClass(name = "org.springframework.data.domain.Page")
public Module pageJacksonModule() {
	return new PageJacksonModule();
}
 
@Bean
@ConditionalOnClass(name = "org.springframework.data.domain.Page")
public Module sortModule() {
	return new SortJacksonModule();
}
 
源代码评论
动弹
沙发等你来抢
 类方法
 同包方法