com.fasterxml.jackson.databind.Module Java Examples
The following examples show how to use
com.fasterxml.jackson.databind.Module.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BootWebUtils.java From onetwo with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: JacksonValueMapperFactory.java From graphql-spqr with Apache License 2.0 | 6 votes |
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)); } }; }
Example #3
Source File: ConfiguredObjectMapper.java From endpoints-java with Apache License 2.0 | 6 votes |
/** * 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; }
Example #4
Source File: ObjectMapperModule.java From jackson-modules-base with Apache License 2.0 | 5 votes |
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>>(); }
Example #5
Source File: ConfiguredObjectMapperTest.java From endpoints-java with Apache License 2.0 | 5 votes |
@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); }
Example #6
Source File: JacksonValueMapperFactory.java From graphql-spqr with Apache License 2.0 | 5 votes |
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; }
Example #7
Source File: JsonSerDeserUtils.java From Eagle with Apache License 2.0 | 5 votes |
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); }
Example #8
Source File: JsonTransformer.java From james-project with Apache License 2.0 | 5 votes |
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); }
Example #9
Source File: JsonExtractor.java From james-project with Apache License 2.0 | 5 votes |
public JsonExtractor(Class<RequestT> type, List<Module> modules) { this.objectMapper = new ObjectMapper() .registerModule(new Jdk8Module()) .registerModule(new GuavaModule()) .registerModules(modules); this.type = type; }
Example #10
Source File: KafkaConsumerOffsetFetcher.java From eagle with Apache License 2.0 | 5 votes |
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); } }
Example #11
Source File: ObjectMapperFactory.java From carbon-apimgt with Apache License 2.0 | 5 votes |
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; }
Example #12
Source File: JsonCodec.java From camunda-bpm-reactor with Apache License 2.0 | 5 votes |
/** * 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); } }
Example #13
Source File: FilterRegistry.java From heroic with Apache License 2.0 | 5 votes |
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; }
Example #14
Source File: JsonRequestMarshaller.java From ob1k with Apache License 2.0 | 5 votes |
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); }
Example #15
Source File: JacksonCodecs.java From immutables with Apache License 2.0 | 5 votes |
/** * 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; } }; }
Example #16
Source File: JsonSerDeserUtils.java From Eagle with Apache License 2.0 | 5 votes |
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); }
Example #17
Source File: DefaultJsonSerializerTest.java From minnal with Apache License 2.0 | 5 votes |
@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)); }
Example #18
Source File: JacksonDecoder.java From feign with Apache License 2.0 | 4 votes |
public JacksonDecoder() { this(Collections.<Module>emptyList()); }
Example #19
Source File: JacksonConfiguration.java From katharsis-framework with Apache License 2.0 | 4 votes |
@Bean public Module parameterNamesModule() { JsonApiModuleBuilder jsonApiModuleBuilder = new JsonApiModuleBuilder(); return jsonApiModuleBuilder.build(resourceRegistry, false); }
Example #20
Source File: HadoopFileSystemModuleTest.java From beam with Apache License 2.0 | 4 votes |
@Test public void testObjectMapperIsAbleToFindModule() { List<Module> modules = ObjectMapper.findModules(ReflectHelpers.findClassLoader()); assertThat(modules, hasItem(Matchers.<Module>instanceOf(HadoopFileSystemModule.class))); }
Example #21
Source File: MonetaryAmountSerializerTest.java From jackson-datatype-money with MIT License | 4 votes |
private JsonMapper.Builder build(final Module module) { return JsonMapper.builder() .addModule(module); }
Example #22
Source File: MonetaryAmountDeserializerTest.java From jackson-datatype-money with MIT License | 4 votes |
private ObjectMapper unit(final Module module) { return new ObjectMapper().registerModule(module); }
Example #23
Source File: AwsModuleTest.java From beam with Apache License 2.0 | 4 votes |
@Test public void testObjectMapperIsAbleToFindModule() { List<Module> modules = ObjectMapper.findModules(ReflectHelpers.findClassLoader()); assertThat(modules, hasItem(Matchers.instanceOf(AwsModule.class))); }
Example #24
Source File: Application.java From spring-repository-plus with Apache License 2.0 | 4 votes |
@Bean public Module datatypeHibernateModule() { return new Hibernate5Module(); }
Example #25
Source File: AwsModuleTest.java From beam with Apache License 2.0 | 4 votes |
@Test public void testObjectMapperIsAbleToFindModule() { List<Module> modules = ObjectMapper.findModules(ReflectHelpers.findClassLoader()); assertThat(modules, hasItem(Matchers.instanceOf(AwsModule.class))); }
Example #26
Source File: JSONConfiguration.java From spring-boot-jpa-data-rest-soft-delete with MIT License | 4 votes |
@Bean public Module Hibernate5Module() { return new Hibernate5Module(); }
Example #27
Source File: ObjectMapperModule.java From jackson-modules-base with Apache License 2.0 | 4 votes |
public ObjectMapperModule registerModule(Class<? extends Module> clazz, Class<? extends Annotation> annotation) { return registerModule(Key.get(clazz, annotation)); }
Example #28
Source File: JWTParserTest.java From java-jwt with MIT License | 4 votes |
@Test public void shouldAddDeserializers() throws Exception { ObjectMapper mapper = mock(ObjectMapper.class); new JWTParser(mapper); verify(mapper).registerModule(any(Module.class)); }
Example #29
Source File: BitcoinConfig.java From consensusj with Apache License 2.0 | 4 votes |
@Bean public Module bitcoinJMapper(NetworkParameters params) { return new RpcServerModule(params); }
Example #30
Source File: MetricsHandler.java From styx with Apache License 2.0 | 4 votes |
public RootMetricsHandler(MetricRegistry data, Optional<Duration> cacheExpiration, Module... modules) { super(data, cacheExpiration, modules); }