@Override public void setMixInAnnotations(Class<?> target, Class<?> mixinSource) { addMixIn(target, mixinSource); }
/** * @deprecated Since 2.5: replaced by a fluent form of the method; {@link #addMixIn(Class, Class)}. */ @Deprecated public final void addMixInAnnotations(Class<?> target, Class<?> mixinSource) { addMixIn(target, mixinSource); }
public UnwiredGeolocationProvider(String url, String key) { this.url = url; this.key = key; objectMapper = new ObjectMapper(); objectMapper.addMixIn(Network.class, NetworkMixIn.class); objectMapper.addMixIn(CellTower.class, CellTowerMixIn.class); objectMapper.addMixIn(WifiAccessPoint.class, WifiAccessPointMixIn.class); }
protected void addMiniConfig(ObjectMapper mapper) { mapper.addMixIn(InstanceInfo.class, MiniInstanceInfoMixIn.class); bindAmazonInfoFilter(mapper); }
private ObjectMapper createMapper(JsonFactory mapping, ClassLoader classLoader) { ObjectMapper mapper = new ObjectMapper(mapping); mapper.addMixIn(MasterSlaveServersConfig.class, MasterSlaveServersConfigMixIn.class); mapper.addMixIn(SingleServerConfig.class, SingleSeverConfigMixIn.class); mapper.addMixIn(Config.class, ConfigMixIn.class); mapper.addMixIn(ReferenceCodecProvider.class, ClassMixIn.class); mapper.addMixIn(AddressResolverGroupFactory.class, ClassMixIn.class); mapper.addMixIn(Codec.class, ClassMixIn.class); mapper.addMixIn(RedissonNodeInitializer.class, ClassMixIn.class); mapper.addMixIn(LoadBalancer.class, ClassMixIn.class); FilterProvider filterProvider = new SimpleFilterProvider() .addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept()); mapper.setFilterProvider(filterProvider); mapper.setSerializationInclusion(Include.NON_NULL); if (classLoader != null) { TypeFactory tf = TypeFactory.defaultInstance() .withClassLoader(classLoader); mapper.setTypeFactory(tf); } return mapper; }
private ObjectMapper createMapper(JsonFactory mapping, ClassLoader classLoader) { ObjectMapper mapper = new ObjectMapper(mapping); mapper.addMixIn(MasterSlaveServersConfig.class, MasterSlaveServersConfigMixIn.class); mapper.addMixIn(SingleServerConfig.class, SingleSeverConfigMixIn.class); mapper.addMixIn(Config.class, ConfigMixIn.class); mapper.addMixIn(ReferenceCodecProvider.class, ClassMixIn.class); mapper.addMixIn(AddressResolverGroupFactory.class, ClassMixIn.class); mapper.addMixIn(Codec.class, ClassMixIn.class); mapper.addMixIn(RedissonNodeInitializer.class, ClassMixIn.class); mapper.addMixIn(LoadBalancer.class, ClassMixIn.class); FilterProvider filterProvider = new SimpleFilterProvider() .addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept()); mapper.setFilterProvider(filterProvider); mapper.setSerializationInclusion(Include.NON_NULL); if (classLoader != null) { TypeFactory tf = TypeFactory.defaultInstance() .withClassLoader(classLoader); mapper.setTypeFactory(tf); } return mapper; }
private ObjectMapper createObjectMapper(KeyFormatter keyFormatter, boolean compact, boolean wrapped) { ObjectMapper newMapper = new ObjectMapper(); SimpleModule jsonModule = new SimpleModule(); jsonModule.setSerializerModifier(EurekaJacksonJsonModifiers.createJsonSerializerModifier(keyFormatter, compact)); newMapper.registerModule(jsonModule); newMapper.setSerializationInclusion(Include.NON_NULL); newMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, wrapped); newMapper.configure(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, false); newMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, wrapped); newMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); newMapper.addMixIn(Applications.class, ApplicationsJsonMixIn.class); if (compact) { addMiniConfig(newMapper); } else { newMapper.addMixIn(InstanceInfo.class, InstanceInfoJsonMixIn.class); } return newMapper; }
public PojoErrorResolver(final ObjectMapper mapper) { this.mapper = mapper.copy().addMixIn(Throwable.class, ThrowableSerializationMixin.class); }
public PojoExceptionResolver(final ObjectMapper mapper) { this.mapper = mapper.copy().addMixIn(Throwable.class, ThrowableSerializationMixin.class); }
/** * Read JSON data from disk and insert those stores. * * @return */ public @Bean AbstractRepositoryPopulatorFactoryBean repositoryPopulator() { ObjectMapper mapper = new ObjectMapper(); mapper.addMixIn(GeoJsonPoint.class, GeoJsonPointMixin.class); mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); Jackson2RepositoryPopulatorFactoryBean factoryBean = new Jackson2RepositoryPopulatorFactoryBean(); factoryBean.setResources(new Resource[] { new ClassPathResource("starbucks-in-nyc.json") }); factoryBean.setMapper(mapper); return factoryBean; }
protected void init(ObjectMapper objectMapper) { objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.setVisibility(objectMapper.getSerializationConfig() .getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); objectMapper.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN); objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); objectMapper.addMixIn(Throwable.class, ThrowableMixIn.class); }
protected void init(ObjectMapper objectMapper) { objectMapper.setSerializationInclusion(Include.NON_NULL); objectMapper.setVisibility(objectMapper.getSerializationConfig() .getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE) .withCreatorVisibility(JsonAutoDetect.Visibility.NONE)); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); objectMapper.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN); objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY); objectMapper.addMixIn(Throwable.class, ThrowableMixIn.class); }
@Before public void before() { mapper.addMixIn(CapabilityContext.class, CapabilityContextMixin.class); }
@Test public void readValueWhenMixinProvidedThenReadsAsSpecificType() throws Exception { mapper.addMixIn(NotWhitelisted.class, NotWhitelistedMixin.class); String content = "{\"@class\":\"org.springframework.security.jackson2.SecurityJackson2ModulesTests$NotWhitelisted\",\"property\":\"bar\"}"; assertThat(mapper.readValue(content, Object.class)).isInstanceOf(NotWhitelisted.class); }
@Test public void readValueWhenHashMapThenReadsAsSpecificType() throws Exception { mapper.addMixIn(NotWhitelisted.class, NotWhitelistedMixin.class); String content = "{\"@class\":\"java.util.HashMap\"}"; assertThat(mapper.readValue(content, Object.class)).isInstanceOf(HashMap.class); }
@Test(description = "read composed schem refs #2900") public void readComposedSchema_ticket2900() { Json.mapper().addMixIn(TestObjectTicket2900.GsonJsonPrimitive.class, TestObjectTicket2900.GsonJsonPrimitiveMixIn.class); Map<String, Schema> schemas = ModelConverters.getInstance().readAll(TestObjectTicket2900.class); Schema model = schemas.get("SomeDTO"); Assert.assertNotNull(model); Map<String, Schema> properties = model.getProperties(); Assert.assertNotNull(properties.get("value")); Assert.assertEquals(properties.get("value").get$ref(), "#/components/schemas/MyJsonPrimitive"); Assert.assertEquals(properties.get("valueWithMixIn").get$ref(), "#/components/schemas/GsonJsonPrimitive"); model = schemas.get("MyJsonPrimitive"); Assert.assertNotNull(model); Assert.assertTrue(((ComposedSchema)model).getOneOf().size() == 2); Assert.assertEquals(((ComposedSchema)model).getOneOf().get(0).getType(), "string"); Assert.assertEquals(((ComposedSchema)model).getOneOf().get(1).getType(), "number"); model = schemas.get("GsonJsonPrimitive"); Assert.assertNotNull(model); Assert.assertTrue(((ComposedSchema)model).getOneOf().size() == 2); Assert.assertEquals(((ComposedSchema)model).getOneOf().get(0).getType(), "string"); Assert.assertEquals(((ComposedSchema)model).getOneOf().get(1).getType(), "number"); Assert.assertNull(model.getProperties()); }
private ObjectMapper createObjectMapper() { ObjectMapper result = new ObjectMapper(); result.addMixIn(Coordinate.class, CoordinateMixin.class); return result; }
/** * @deprecated Since 2.5: replaced by a fluent form of the method; {@link #addMixIn(Class, Class)}. */ @Deprecated public final void addMixInAnnotations(Class<?> target, Class<?> mixinSource) { addMixIn(target, mixinSource); }
@Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { for (HttpMessageConverter<?> httpMessageConverter : converters) { if (httpMessageConverter instanceof MappingJackson2HttpMessageConverter) { final MappingJackson2HttpMessageConverter converter = (MappingJackson2HttpMessageConverter) httpMessageConverter; converter.getObjectMapper().addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class); } } }
protected ObjectMapper newObjectMapper(Configuration configuration, ScanResult scanResult, ConnectionReader connectionReader) { Boolean property = PropertyHelper.getProperty(configuration, RestServerV2.JSON_PRETTYPRINT_ENABLE); final boolean prettyPrint = property != null && property; ObjectMapper mapper = prettyPrint ? JSONUtil.prettyMapper() : JSONUtil.mapper(); JSONUtil.registerStorageTypes(mapper, scanResult, connectionReader); mapper.addMixIn(VirtualDatasetUI.class, VirtualDatasetUIMixin.class); return mapper; } }