Java Code Examples for com.fasterxml.jackson.databind.module.SimpleModule#setDeserializerModifier()
The following examples show how to use
com.fasterxml.jackson.databind.module.SimpleModule#setDeserializerModifier() .
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: AbstractStoresTest.java From alfresco-simple-content-stores with Apache License 2.0 | 6 votes |
/** * Configures and constructs a Resteasy client to use for calling the Alfresco Public ReST API in the dockerised deployment. * * @return the configured client */ protected static ResteasyClient setupResteasyClient() { final SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new RestAPIBeanDeserializerModifier()); final ResteasyJackson2Provider resteasyJacksonProvider = new ResteasyJackson2Provider(); final ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_EMPTY); mapper.registerModule(module); resteasyJacksonProvider.setMapper(mapper); final LocalResteasyProviderFactory resteasyProviderFactory = new LocalResteasyProviderFactory(new ResteasyProviderFactoryImpl()); resteasyProviderFactory.register(resteasyJacksonProvider); // will cause a warning regarding Jackson provider which is already registered RegisterBuiltin.register(resteasyProviderFactory); resteasyProviderFactory.register(new MultiValuedParamConverterProvider()); final ResteasyClient client = new ResteasyClientBuilderImpl().providerFactory(resteasyProviderFactory).build(); return client; }
Example 2
Source File: ObjectMappers.java From glowroot with Apache License 2.0 | 6 votes |
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; }
Example 3
Source File: StandaloneConfiguration.java From gravitee-gateway with Apache License 2.0 | 6 votes |
@Bean public ObjectMapper objectMapper() { ObjectMapper mapper = new GraviteeMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config, final JavaType type, BeanDescription beanDesc, final JsonDeserializer<?> deserializer) { return new JsonDeserializer<Enum>() { @Override public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass(); return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase()); } }; } }); mapper.registerModule(module); return mapper; }
Example 4
Source File: AdditionalPropertiesDeserializer.java From autorest-clientruntime-for-java with MIT License | 6 votes |
/** * Gets a module wrapping this serializer as an adapter for the Jackson * ObjectMapper. * * @param mapper the object mapper for default deserializations * @return a simple module to be plugged onto Jackson ObjectMapper. */ public static SimpleModule getModule(final ObjectMapper mapper) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { for (Class<?> c : TypeToken.of(beanDesc.getBeanClass()).getTypes().classes().rawTypes()) { Field[] fields = c.getDeclaredFields(); for (Field field : fields) { if ("additionalProperties".equalsIgnoreCase(field.getName())) { JsonProperty property = field.getAnnotation(JsonProperty.class); if (property != null && property.value().isEmpty()) { return new AdditionalPropertiesDeserializer(beanDesc.getBeanClass(), deserializer, mapper); } } } } return deserializer; } }); return module; }
Example 5
Source File: FlatteningDeserializer.java From autorest-clientruntime-for-java with MIT License | 6 votes |
/** * Gets a module wrapping this serializer as an adapter for the Jackson * ObjectMapper. * * @param mapper the object mapper for default deserializations * @return a simple module to be plugged onto Jackson ObjectMapper. */ public static SimpleModule getModule(final ObjectMapper mapper) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (BeanDeserializer.class.isAssignableFrom(deserializer.getClass())) { // Apply flattening deserializer on all POJO types. return new FlatteningDeserializer(beanDesc.getBeanClass(), deserializer, mapper); } else { return deserializer; } } }); return module; }
Example 6
Source File: ObjectMapperFactory.java From vividus with Apache License 2.0 | 6 votes |
public static ObjectMapper createWithCaseInsensitiveEnumDeserializer() { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<Enum<?>> modifyEnumDeserializer(DeserializationConfig config, final JavaType type, BeanDescription beanDescription, final JsonDeserializer<?> deserializer) { return new JsonDeserializer<>() { @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Enum<?> deserialize(JsonParser parser, DeserializationContext context) throws IOException { return Enum.valueOf((Class<? extends Enum>) type.getRawClass(), parser.getValueAsString().toUpperCase()); } }; } }); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(module); return objectMapper; }
Example 7
Source File: AdditionalPropertiesDeserializer.java From botbuilder-java with MIT License | 6 votes |
/** * Gets a module wrapping this serializer as an adapter for the Jackson * ObjectMapper. * * @param mapper the object mapper for default deserializations * @return a simple module to be plugged onto Jackson ObjectMapper. */ public static SimpleModule getModule(final ObjectMapper mapper) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { for (Class<?> c : TypeToken.of(beanDesc.getBeanClass()).getTypes().classes().rawTypes()) { Field[] fields = c.getDeclaredFields(); for (Field field : fields) { if ("additionalProperties".equalsIgnoreCase(field.getName())) { JsonProperty property = field.getAnnotation(JsonProperty.class); if (property != null && property.value().isEmpty()) { return new AdditionalPropertiesDeserializer(beanDesc.getBeanClass(), deserializer, mapper); } } } } return deserializer; } }); return module; }
Example 8
Source File: FlatteningDeserializer.java From botbuilder-java with MIT License | 6 votes |
/** * Gets a module wrapping this serializer as an adapter for the Jackson * ObjectMapper. * * @param mapper the object mapper for default deserializations * @return a simple module to be plugged onto Jackson ObjectMapper. */ public static SimpleModule getModule(final ObjectMapper mapper) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (BeanDeserializer.class.isAssignableFrom(deserializer.getClass())) { // Apply flattening deserializer on all POJO types. return new FlatteningDeserializer(beanDesc.getBeanClass(), deserializer, mapper); } else { return deserializer; } } }); return module; }
Example 9
Source File: GenerateBatch.java From openapi-generator with Apache License 2.0 | 6 votes |
static SimpleModule getCustomDeserializationModel(final File includesDir) { // Create a module which loads our config files, but supports a special "!include" key which can point to an existing config file. // This allows us to create a sort of meta-config which holds configs which are otherwise required at CLI time (via generate task). // That is, this allows us to create a wrapper config for generatorName, inputSpec, outputDir, etc. SimpleModule module = new SimpleModule("GenerateBatch"); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription bd, JsonDeserializer<?> original) { JsonDeserializer<?> result; if (bd.getBeanClass() == DynamicSettings.class) { result = new DynamicSettingsRefSupport(original, includesDir); } else { result = original; } return result; } }); return module; }
Example 10
Source File: ObjectMapperFactory.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
private static ObjectMapper configureObjectMapper( ObjectMapper objectMapper, boolean shouldIncludeRawResponses) { if (shouldIncludeRawResponses) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) { return new RawResponseDeserializer(deserializer); } return deserializer; } }); objectMapper.registerModule(module); } objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
Example 11
Source File: ObjectMapperFactory.java From client-sdk-java with Apache License 2.0 | 6 votes |
private static ObjectMapper configureObjectMapper( ObjectMapper objectMapper, boolean shouldIncludeRawResponses) { if (shouldIncludeRawResponses) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) { return new RawResponseDeserializer(deserializer); } return deserializer; } }); objectMapper.registerModule(module); } objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
Example 12
Source File: ObjectMapperFactory.java From web3sdk with Apache License 2.0 | 5 votes |
private static ObjectMapper configureObjectMapper( ObjectMapper objectMapper, boolean shouldIncludeRawResponses) { if (shouldIncludeRawResponses) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier( new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer( DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) { return new RawResponseDeserializer(deserializer); } return deserializer; } }); objectMapper.registerModule(module); } objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
Example 13
Source File: ObjectMapperFactory.java From web3j with Apache License 2.0 | 5 votes |
private static ObjectMapper configureObjectMapper( ObjectMapper objectMapper, boolean shouldIncludeRawResponses) { if (shouldIncludeRawResponses) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier( new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer( DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) { return new RawResponseDeserializer(deserializer); } return deserializer; } }); objectMapper.registerModule(module); } objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper; }
Example 14
Source File: ObjectMapperResolver.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
public ObjectMapperResolver() { mapper = new GraviteeMapper(); //because Permissions are represented as char[] mapper.enable(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS); // register filter provider registerFilterProvider(); SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config, final JavaType type, BeanDescription beanDesc, final JsonDeserializer<?> deserializer) { return new JsonDeserializer<Enum>() { @Override public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass(); return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase()); } }; } }); module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) { @Override public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(value.name().toLowerCase()); } }); mapper.registerModule(module); }
Example 15
Source File: ObjectMapperResolver.java From gravitee-management-rest-api with Apache License 2.0 | 5 votes |
public ObjectMapperResolver() { mapper = new GraviteeMapper(); //because Permissions are represented as char[] mapper.enable(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS); // register filter provider registerFilterProvider(); SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config, final JavaType type, BeanDescription beanDesc, final JsonDeserializer<?> deserializer) { return new JsonDeserializer<Enum>() { @Override public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass(); return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase()); } }; } }); module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) { @Override public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(value.name().toLowerCase()); } }); mapper.registerModule(module); mapper.registerModule(new JavaTimeModule()); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); }
Example 16
Source File: JsonUtil.java From hawkular-alerts with Apache License 2.0 | 5 votes |
private JsonUtil() { mapper = new ObjectMapper(); SimpleModule simpleModule = new SimpleModule(); simpleModule.setDeserializerModifier(new JacksonDeserializer.AlertThinDeserializer()); mapperThin = new ObjectMapper(); mapperThin.registerModule(simpleModule); }
Example 17
Source File: AbstractMetricsDispatcher.java From gradle-metrics-plugin with Apache License 2.0 | 5 votes |
/** * Register Jackson module that maps enums as lowercase. Per http://stackoverflow.com/a/24173645. */ @SuppressWarnings("rawtypes") private static void registerEnumModule(ObjectMapper mapper) { SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config, final JavaType type, BeanDescription beanDesc, final JsonDeserializer<?> deserializer) { return new JsonDeserializer<Enum>() { @Override public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { @SuppressWarnings("unchecked") Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass(); return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase()); } }; } }); module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) { @Override public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(value.name().toLowerCase()); } }); mapper.registerModule(module); }
Example 18
Source File: ObjectMapperResolver.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
public ObjectMapperResolver() { mapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config, final JavaType type, BeanDescription beanDesc, final JsonDeserializer<?> deserializer) { return new JsonDeserializer<Enum>() { @Override public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass(); return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase()); } }; } }); module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) { @Override public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(value.name().toLowerCase()); } }); module.addSerializer(Instant.class, new StdSerializer<Instant>(Instant.class) { @Override public void serialize(Instant instant, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeNumber(instant.toEpochMilli()); } }); module.addDeserializer(JWK.class, new StdDeserializer<JWK>(JWK.class) { @Override public JWK deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); String kty = node.get("kty").asText(); if (kty == null) { return null; } JWK jwk = null; switch (kty) { case "RSA": jwk = jsonParser.getCodec().treeToValue(node, RSAKey.class); break; case "EC": jwk = jsonParser.getCodec().treeToValue(node, ECKey.class); break; case "oct": jwk = jsonParser.getCodec().treeToValue(node, OCTKey.class); break; case "OKP": jwk = jsonParser.getCodec().treeToValue(node, OKPKey.class); break; } return jwk; } }); mapper.addMixIn(Domain.class, MixIn.class); mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.registerModule(module); mapper.registerModule(new Jdk8Module()); mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS); }
Example 19
Source File: BeanConfigFactoryManager.java From logsniffer with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") @PostConstruct private void initJsonMapper() { final SimpleModule module = new SimpleModule(); module.setDeserializerModifier(new BeanDeserializerModifier() { @Override public JsonDeserializer<?> modifyDeserializer(final DeserializationConfig config, final BeanDescription beanDesc, final JsonDeserializer<?> deserializer) { if (ConfiguredBean.class.isAssignableFrom(beanDesc.getBeanClass())) { return new ConfiguredBeanDeserializer(deserializer); } return deserializer; } }); jsonMapper.registerModule(module); if (postConstructors != null) { for (final BeanPostConstructor<?> bpc : postConstructors) { mappedPostConstrucors.put(bpc.getClass(), bpc); } } // Register sub beans final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); final AssignableTypeFilter filter4configBenas = new AssignableTypeFilter(ConfiguredBean.class); scanner.addIncludeFilter(filter4configBenas); for (final BeanDefinition bd : scanner.findCandidateComponents("com.logsniffer")) { try { final Class<? extends ConfiguredBean> clazz = (Class<? extends ConfiguredBean>) Class .forName(bd.getBeanClassName()); final JsonTypeName jsonNameAnnotation = clazz.getAnnotation(JsonTypeName.class); final List<String> names = new ArrayList<String>(); configBeanNames.put(clazz, names); if (jsonNameAnnotation != null) { names.add(jsonNameAnnotation.value()); if (jsonNameAnnotation.deprecated() != null) { for (final String dep : jsonNameAnnotation.deprecated()) { names.add(dep); } } } names.add(clazz.getSimpleName()); logger.debug("Registered JSON type {} for following names: {}", clazz, names); } catch (final ClassNotFoundException e) { logger.warn("Failed to register JSON type name for " + bd.getBeanClassName(), e); } } }