@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)); }
@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()); }
@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(); }
@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())); }
@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" + "} ]"); }
/** * 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); }
@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; }
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)); } }; }
/** * 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; }
@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); }
@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); }
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; }
@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; }
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); } }
@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(); } }); }
@Provides public JacksonSerializer.Builder getJacksonSerializer(Injector injector, @JacksonModulesP Set<Module> jacksonModules) { final JacksonSerializer.Builder ret = JacksonSerializer.builder().withInjectionBindings(new GuiceAnnotationIntrospector(), new GuiceInjectableValues(injector)); for (final Module jacksonModule : jacksonModules) { ret.registerModule(jacksonModule); } // we block this module from being installed if found on the classpath because it breaks // our normal Guice injection during deserialization. This shouldn't be a problem because // things which use this (like Jersey) don't use JacksonSerializer.Builder to get their // deserializers anyway. If it's ever a problem, we can provide an optional to disable it. ret.blockModuleClassName("com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule"); return ret; }
private ObjectMapper mapperFromJSONFactory(JsonFactory jsonFactory) { final ObjectMapper mapper = new ObjectMapper(jsonFactory); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); // the JaxB annotations module bound by Jersey breaks our normal serialization for // some reason, so we need to block it if it is found on the classpath somehow final ImmutableSet<String> blockedModuleClassNames = blockedModuleClassNamesB.build(); for (final Module foundModule : ObjectMapper.findModules()) { if (!blockedModuleClassNames.contains(foundModule.getClass().getName())) { mapper.registerModule(foundModule); } else { log.warn("Blocked installation of discovered module {}", foundModule); } } // modules are ordered by name for determinism, see field declaration for (final Module module : modules.build()) { mapper.registerModule(module); } return mapper; }
public static ObjectMapper create(Module... extraModules) { SimpleModule module = new SimpleModule(); module.addSerializer(boolean.class, new BooleanSerializer(Boolean.class)); module.addSerializer(Enum.class, new EnumSerializer(Enum.class)); module.setDeserializerModifier(new EnumDeserializerModifier()); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module); mapper.registerModule(new GuavaModule()); for (Module extraModule : extraModules) { mapper.registerModule(extraModule); } mapper.setSerializationInclusion(Include.NON_ABSENT); return mapper; }
@Bean public Module facilityModule() { return new SimpleModule("geometryModule") {{ final JsonMapper jsonMapper = new JsonMapper(); addSerializer(Geometry.class, new GeojsonSerializer<>(jsonMapper)); addDeserializer(Geometry.class, new GeojsonDeserializer<>(jsonMapper, Geometry.class)); addSerializer(Polygon.class, new GeojsonSerializer<>(jsonMapper)); addDeserializer(Polygon.class, new GeojsonDeserializer<>(jsonMapper, Polygon.class)); addSerializer(Point.class, new GeojsonSerializer<>(jsonMapper)); addDeserializer(Point.class, new GeojsonDeserializer<>(jsonMapper, Point.class)); addSerializer(Feature.class, new GeojsonSerializer<>(jsonMapper)); addSerializer(Phone.class, new PhoneSerializer()); addSerializer(Time.class, new ToStringSerializer()); }}; }
@Override public void setupModule(Module.SetupContext context) { super.setupModule(context); context.setMixInAnnotations(Id.class, IdConfiguration.class); context.setMixInAnnotations(BrandRef.class, ResourceRefConfiguration.class); context.setMixInAnnotations(TopicRef.class, ResourceRefConfiguration.class); context.setMixInAnnotations(ItemRef.class, ItemRefConfiguration.class); context.setMixInAnnotations(EpisodeRef.class, ItemRefConfiguration.class); context.setMixInAnnotations(SongRef.class, ItemRefConfiguration.class); context.setMixInAnnotations(FilmRef.class, ItemRefConfiguration.class); context.setMixInAnnotations(ClipRef.class, ItemRefConfiguration.class); context.setMixInAnnotations(SeriesRef.class, SeriesRefConfiguration.class); context.setMixInAnnotations(BroadcastRef.class, BroadcastRefConfiguration.class); context.setMixInAnnotations(ScheduleRef.class, ScheduleRefConfiguration.class); context.setMixInAnnotations( ScheduleRef.Entry.class, ScheduleRefConfiguration.Entry.class ); context.setMixInAnnotations(Timestamp.class, TimestampConfiguration.class); SimpleDeserializers desers = new SimpleDeserializers(); context.addDeserializers(desers); }
@Override protected void configure() { Multibinder<Module> jacksonModuleBinder = Multibinder.newSetBinder(binder(), Module.class); jacksonModuleBinder.addBinding().to(AvroJacksonModule.class); install(MultibindingsScanner.asModule()); }
@Inject void init( DynamicBindingProvider<Set<Module>> jacksonModules, DynamicBindingProvider<Set<SerializationFeatureFlag>> serializationFeatureFlag, DynamicBindingProvider<Set<DeserializationFeatureFlag>> deserializationFeatureFlag, DynamicBindingProvider<Set<MapperFeatureFlag>> mapperFeatureFlag, DynamicBindingProvider<Set<JsonGeneratorFeatureFlag>> jsonGeneratorFeatureFlag, DynamicBindingProvider<Set<JsonParserFeatureFlag>> jsonParserFeatureFlag) { this.jacksonModules = jacksonModules.get(clientBindingAnnotation); this.serializationFeatureFlag = serializationFeatureFlag.get(clientBindingAnnotation); this.deserializationFeatureFlag = deserializationFeatureFlag.get(clientBindingAnnotation); this.mapperFeatureFlag = mapperFeatureFlag.get(clientBindingAnnotation); this.jsonGeneratorFeatureFlag = jsonGeneratorFeatureFlag.get(clientBindingAnnotation); this.jsonParserFeatureFlag = jsonParserFeatureFlag.get(clientBindingAnnotation); }
@Override protected void configure() { AnnotatedObjectMapperProvider provider = new AnnotatedObjectMapperProvider(getBindingAnnotation()); bind(ObjectMapper.class).annotatedWith(getBindingAnnotation()).toProvider(provider) .asEagerSingleton(); bindDynamicProvider(ObjectMapper.class); expose(ObjectMapper.class).annotatedWith(getBindingAnnotation()); bind(JacksonJsonProvider.class).annotatedWith(getBindingAnnotation()) .toProvider(new JacksonJsonGuiceProvider(getBindingAnnotation())); expose(JacksonJsonProvider.class).annotatedWith(getBindingAnnotation()); bindDynamicProvider(new TypeLiteral<Set<Module>>() { }); bindDynamicProvider(new TypeLiteral<Set<SerializationFeatureFlag>>() { }); bindDynamicProvider(new TypeLiteral<Set<DeserializationFeatureFlag>>() { }); bindDynamicProvider(new TypeLiteral<Set<JsonGeneratorFeatureFlag>>() { }); bindDynamicProvider(new TypeLiteral<Set<JsonParserFeatureFlag>>() { }); bindDynamicProvider(new TypeLiteral<Set<MapperFeatureFlag>>() { }); }
@Inject ObjectMapperProvider(Set<Module> jacksonModules, Set<SerializationFeatureFlag> serializationFeatureFlag, Set<DeserializationFeatureFlag> deserializationFeatureFlag, Set<MapperFeatureFlag> mapperFeatureFlag, Set<JsonGeneratorFeatureFlag> jsonGeneratorFeatureFlag, Set<JsonParserFeatureFlag> jsonParserFeatureFlag) { this.serializationFeatureFlag = serializationFeatureFlag; this.deserializationFeatureFlag = deserializationFeatureFlag; this.mapperFeatureFlag = mapperFeatureFlag; this.jsonGeneratorFeatureFlag = jsonGeneratorFeatureFlag; this.jsonParserFeatureFlag = jsonParserFeatureFlag; this.jacksonModules = jacksonModules; }
@Override protected void configure() { Multibinder<Module> jacksonModuleBinder = Multibinder.newSetBinder(binder(), Module.class); jacksonModuleBinder.addBinding().to(TestModule.class); install(new JacksonModule()); }
@Override public void setupModule(Module.SetupContext sc) { sc.setMixInAnnotations(MeterValuesRequest.class, MeterValue15Mixin.class); // Enums from CP sc.setMixInAnnotations(ocpp.cp._2012._06.AuthorizationStatus.class, EnumMixin.class); sc.setMixInAnnotations(AvailabilityStatus.class, EnumMixin.class); sc.setMixInAnnotations(AvailabilityType.class, EnumMixin.class); sc.setMixInAnnotations(CancelReservationStatus.class, EnumMixin.class); sc.setMixInAnnotations(ClearCacheStatus.class, EnumMixin.class); sc.setMixInAnnotations(ConfigurationStatus.class, EnumMixin.class); sc.setMixInAnnotations(ocpp.cp._2012._06.DataTransferStatus.class, EnumMixin.class); sc.setMixInAnnotations(RemoteStartStopStatus.class, EnumMixin.class); sc.setMixInAnnotations(ReservationStatus.class, EnumMixin.class); sc.setMixInAnnotations(ResetStatus.class, EnumMixin.class); sc.setMixInAnnotations(ResetType.class, EnumMixin.class); sc.setMixInAnnotations(UnlockStatus.class, EnumMixin.class); sc.setMixInAnnotations(UpdateStatus.class, EnumMixin.class); sc.setMixInAnnotations(UpdateType.class, EnumMixin.class); // Enums from CS sc.setMixInAnnotations(ocpp.cs._2012._06.AuthorizationStatus.class, EnumMixin.class); sc.setMixInAnnotations(ChargePointErrorCode.class, EnumMixin.class); sc.setMixInAnnotations(ChargePointStatus.class, EnumMixin.class); sc.setMixInAnnotations(ocpp.cs._2012._06.DataTransferStatus.class, EnumMixin.class); sc.setMixInAnnotations(DiagnosticsStatus.class, EnumMixin.class); sc.setMixInAnnotations(FirmwareStatus.class, EnumMixin.class); sc.setMixInAnnotations(Location.class, EnumMixin.class); sc.setMixInAnnotations(Measurand.class, EnumMixin.class); sc.setMixInAnnotations(ReadingContext.class, EnumMixin.class); sc.setMixInAnnotations(RegistrationStatus.class, EnumMixin.class); sc.setMixInAnnotations(UnitOfMeasure.class, EnumMixin.class); sc.setMixInAnnotations(ValueFormat.class, EnumMixin.class); }
@Test public void setModules() { NumberSerializer serializer = new NumberSerializer(Integer.class); SimpleModule module = new SimpleModule(); module.addSerializer(Integer.class, serializer); this.factory.setModules(Arrays.asList(new Module[]{module})); this.factory.afterPropertiesSet(); ObjectMapper objectMapper = this.factory.getObject(); Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next(); assertSame(serializer, serializers.findSerializer(null, SimpleType.construct(Integer.class), null)); }
@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.writeFieldName("content"); serializers.defaultSerializeValue(value.getContent(),gen); gen.writeEndObject(); } }); }
@Override public Set<Class<Module>> getModuleClasses() throws ClassNotFoundException { HashSet<Class<Module>> classes = new HashSet<>(); for (String className : moduleClassNames) { classes.add((Class<Module>)Class.forName(className)); } return classes; }
@Override public Object execute() throws Exception { for (JacksonModulesService provider : managerService.getModulesProviders()) { for (Class<Module> clazz : provider.getModuleClasses()) { System.out.println(clazz.getName()); } } return null; }
@Test public void addsHibernateSupportToJackson() throws Exception { final ObjectMapper objectMapperFactory = mock(ObjectMapper.class); final Bootstrap<?> bootstrap = mock(Bootstrap.class); when(bootstrap.getObjectMapper()).thenReturn(objectMapperFactory); bundle.initialize(bootstrap); final ArgumentCaptor<Module> captor = ArgumentCaptor.forClass(Module.class); verify(objectMapperFactory).registerModule(captor.capture()); assertThat(captor.getValue()).isInstanceOf(Hibernate4Module.class); }
@Override public List<? extends Module> getJacksonModules() { // Register Jackson module for any classes we need to be able to use in JSON queries or ingestion specs. return ImmutableList.of( new SimpleModule(getClass().getSimpleName()).registerSubtypes( new NamedType(ExampleSumAggregatorFactory.class, ExampleSumAggregatorFactory.TYPE_NAME), new NamedType(ExampleExtractionFn.class, ExampleExtractionFn.TYPE_NAME) ) ); }
private void assertDeserialize(Module module) throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module); NameAndAge nameAndAge = mapper.readValue("{\"name\":\"spring\",\"age\":100}", NameAndAge.class); assertThat(nameAndAge.getName()).isEqualTo("spring"); assertThat(nameAndAge.getAge()).isEqualTo(100); }