List of usage examples for com.fasterxml.jackson.databind ObjectMapper getSerializationConfig
public SerializationConfig getSerializationConfig()
From source file:org.springframework.cloud.stream.config.MessageChannelConfigurerTests.java
@Test public void testObjectMapperConfig() throws Exception { CompositeMessageConverter converters = (CompositeMessageConverter) messageConverterFactory .getMessageConverterForType(MimeTypeUtils.APPLICATION_JSON); for (MessageConverter converter : converters.getConverters()) { DirectFieldAccessor converterAccessor = new DirectFieldAccessor(converter); ObjectMapper objectMapper = (ObjectMapper) converterAccessor.getPropertyValue("objectMapper"); // assert that the ObjectMapper used by the converters is compliant with the // Boot configuration assertThat(!objectMapper.getSerializationConfig() .isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) .withFailMessage("SerializationFeature 'WRITE_DATES_AS_TIMESTAMPS' should be disabled"); // assert that the globally set bean is used by the converters assertThat(objectMapper).isSameAs(this.objectMapper); }/*w w w . jav a 2 s . co m*/ }
From source file:com.google.api.server.spi.config.jsonwriter.JacksonResourceSchemaProvider.java
@Override public ResourceSchema getResourceSchema(TypeToken<?> type, ApiConfig config) { ResourceSchema schema = super.getResourceSchema(type, config); if (schema != null) { return schema; }/*from www . j ava2s . c o m*/ ObjectMapper objectMapper = ObjectMapperUtil.createStandardObjectMapper(config.getSerializationConfig()); JavaType javaType = objectMapper.getTypeFactory().constructType(type.getRawType()); BeanDescription beanDescription = objectMapper.getSerializationConfig().introspect(javaType); ResourceSchema.Builder schemaBuilder = ResourceSchema.builderForType(type.getRawType()); Set<String> genericDataFieldNames = getGenericDataFieldNames(type); for (BeanPropertyDefinition definition : beanDescription.findProperties()) { TypeToken<?> propertyType = getPropertyType(type, toMethod(definition.getGetter()), toMethod(definition.getSetter()), definition.getField(), config); String name = definition.getName(); if (genericDataFieldNames == null || genericDataFieldNames.contains(name)) { if (hasUnresolvedType(propertyType)) { logger.warning("skipping field '" + name + "' of type '" + propertyType + "' because it is unresolved."); continue; } if (propertyType != null) { schemaBuilder.addProperty(name, ResourcePropertySchema.of(propertyType)); } else { logger.warning("No type found for property '" + name + "' on class '" + type + "'."); } } else { logger.fine("skipping field '" + name + "' because it's not a Java client model field."); } } return schemaBuilder.build(); }
From source file:eu.modaclouds.sla.mediator.Utils.java
private <E> void printJson(E e) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector introspector = new JacksonAnnotationIntrospector(); // mapper.getDeserializationConfig().setAnnotationIntrospector(introspector); mapper.getSerializationConfig().with(introspector); System.out.println(mapper.writeValueAsString(e)); }
From source file:org.springframework.data.rest.webmvc.json.JacksonMetadata.java
/** * Creates a new {@link JacksonMetadata} instance for the given {@link ObjectMapper} and type. * //from w ww . j a v a 2 s . c o m * @param mapper must not be {@literal null}. * @param type must not be {@literal null}. */ public JacksonMetadata(ObjectMapper mapper, Class<?> type) { Assert.notNull(mapper, "ObjectMapper must not be null!"); Assert.notNull(type, "Type must not be null!"); this.mapper = mapper; SerializationConfig serializationConfig = mapper.getSerializationConfig(); JavaType javaType = serializationConfig.constructType(type); BeanDescription description = serializationConfig.introspect(javaType); this.definitions = description.findProperties(); this.isValue = description.findJsonValueMethod() != null; DeserializationConfig deserializationConfig = mapper.getDeserializationConfig(); JavaType deserializationType = deserializationConfig.constructType(type); this.deserializationDefinitions = deserializationConfig.introspect(deserializationType).findProperties(); }
From source file:net.logstash.logback.marker.ObjectFieldsAppendingMarker.java
/** * Gets a {@link SerializerProvider} configured with the {@link ObjectMapper}'s {@link SerializationConfig} * ({@link ObjectMapper#getSerializationConfig()}) to be used for serialization. * <p>//from w ww. j a va2 s. com * Note that the {@link ObjectMapper}'s {@link SerializerProvider} ({@link ObjectMapper#getSerializerProvider()}) * cannot be used directly, because the {@link SerializerProvider}'s {@link SerializationConfig} ({@link SerializerProvider#getConfig()}) is null, * which causes NullPointerExceptions when it is used. */ private SerializerProvider getSerializerProvider(ObjectMapper mapper) { SerializerProvider provider = serializerProviders.get(mapper); if (provider == null) { SerializerProvider newProvider = ((DefaultSerializerProvider) mapper.getSerializerProvider()) .createInstance(mapper.getSerializationConfig(), mapper.getSerializerFactory()); SerializerProvider existingProvider = serializerProviders.putIfAbsent(mapper, newProvider); provider = (existingProvider == null) ? newProvider : existingProvider; } return provider; }
From source file:io.apptik.comm.jus.converter.JacksonConverterFactoryTest.java
@Before public void setUp() { queue = Jus.newRequestQueue();/*from www . j av a2 s.com*/ SimpleModule module = new SimpleModule(); module.addSerializer(AnInterface.class, new AnInterfaceSerializer()); module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer()); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module); mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); RetroProxy retroProxy = new RetroProxy.Builder().baseUrl(server.url("/").toString()) .addConverterFactory(JacksonConverterFactory.create(mapper)).requestQueue(queue).build(); service = retroProxy.create(Service.class); }
From source file:retrofit.JacksonConverterFactoryTest.java
@Before public void setUp() { SimpleModule module = new SimpleModule(); module.addSerializer(AnInterface.class, new AnInterfaceSerializer()); module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer()); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module);// www.ja va 2 s . co m mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")) .addConverterFactory(JacksonConverterFactory.create(mapper)).build(); service = retrofit.create(Service.class); }
From source file:org.brutusin.json.impl.JacksonCodec.java
public JacksonCodec(ObjectMapper mapper, JacksonFactoryWrapper schemaFactory) { if (mapper == null) { mapper = new ObjectMapper(); mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); SimpleModule testModule = new SimpleModule("json-provider-module", new Version(1, 0, 0, null, "org.brutusin", "json-provider")); testModule.addSerializer(new JsonNodeSerializer()); testModule.addDeserializer(JsonNode.class, new JsonNodeDeserializer()); testModule.addSerializer(new InputStreamSerializer()); testModule.addDeserializer(InputStream.class, new InputStreamDeserializer()); testModule.addDeserializer(MetaDataInputStream.class, new InputStreamDeserializer()); mapper.registerModule(testModule); }/*from w ww .ja v a 2 s .co m*/ if (schemaFactory == null) { schemaFactory = new JacksonFactoryWrapper(new HashMap<Class, String>(DEFAULT_FORMAT_MAP)); } this.mapper = mapper; this.schemaFactory = schemaFactory; }
From source file:com.apteligent.ApteligentJavaClient.java
private ObjectMapper getObjectMapper() { // configure and return ObjectMapper for JSON->Java Object de-serialization ObjectMapper mapper = new ObjectMapper(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true); return mapper; }
From source file:capital.scalable.restdocs.jackson.FieldDocumentationGeneratorTest.java
private ObjectMapper createMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY)); return mapper; }