@Override public final AnnotationIntrospector getAnnotationIntrospector() { return _config.getAnnotationIntrospector(); }
protected AbstractModelConverter(ObjectMapper mapper, TypeNameResolver typeNameResolver) { mapper.registerModule( new SimpleModule("swagger", Version.unknownVersion()) { @Override public void setupModule(SetupContext context) { context.insertAnnotationIntrospector(new SwaggerAnnotationIntrospector()); } }); _mapper = mapper; _typeNameResolver = typeNameResolver; _intr = mapper.getSerializationConfig().getAnnotationIntrospector(); }
/** * Method called to find filter that is configured to be used with bean * serializer being built, if any. */ protected Object findFilterId(SerializationConfig config, BeanDescription beanDesc) { return config.getAnnotationIntrospector().findFilterId((Annotated)beanDesc.getClassInfo()); }
private List<String> getIgnoredProperties(BeanDescription beanDescription) { AnnotationIntrospector introspector = _mapper.getSerializationConfig().getAnnotationIntrospector(); String[] ignored = introspector.findPropertiesToIgnore(beanDescription.getClassInfo(), true); return ignored == null ? Collections.emptyList() : Arrays.asList(ignored); }
List<BeanPropertyDefinition> properties) AnnotationIntrospector intr = config.getAnnotationIntrospector(); HashMap<Class<?>,Boolean> ignores = new HashMap<Class<?>,Boolean>(); Iterator<BeanPropertyDefinition> it = properties.iterator();
/** * Helper method to check whether global settings and/or class * annotations for the bean class indicate that static typing * (declared types) should be used for properties. * (instead of dynamic runtime types). * * @since 2.1 (earlier had variant with additional 'property' parameter) */ protected boolean usesStaticTyping(SerializationConfig config, BeanDescription beanDesc, TypeSerializer typeSer) { /* 16-Aug-2010, tatu: If there is a (value) type serializer, we cannot force * static typing; that would make it impossible to handle expected subtypes */ if (typeSer != null) { return false; } AnnotationIntrospector intr = config.getAnnotationIntrospector(); JsonSerialize.Typing t = intr.findSerializationTyping(beanDesc.getClassInfo()); if (t != null && t != JsonSerialize.Typing.DEFAULT_TYPING) { return (t == JsonSerialize.Typing.STATIC); } return config.isEnabled(MapperFeature.USE_STATIC_TYPING); }
@Override protected JsonEndpointConfig _configForWriting(final ObjectMapper mapper, final Annotation[] annotations, final Class<?> defaultView) { final AnnotationIntrospector customIntrospector = mapper.getSerializationConfig().getAnnotationIntrospector(); // Set the custom (user) introspector to be the primary one. final ObjectMapper filteringMapper = mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(customIntrospector, new JacksonAnnotationIntrospector() { @Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } })); return super._configForWriting(filteringMapper, annotations, defaultView); }
/** * Method called to create a type information serializer for values of given * non-container property * if one is needed. If not needed (no polymorphic handling configured), should * return null. * * @param baseType Declared type to use as the base type for type information serializer * * @return Type serializer to use for property values, if one is needed; null if not. */ public TypeSerializer findPropertyTypeSerializer(JavaType baseType, SerializationConfig config, AnnotatedMember accessor) throws JsonMappingException { AnnotationIntrospector ai = config.getAnnotationIntrospector(); TypeResolverBuilder<?> b = ai.findPropertyTypeResolver(config, accessor, baseType); TypeSerializer typeSer; // Defaulting: if no annotations on member, check value class if (b == null) { typeSer = createTypeSerializer(config, baseType); } else { Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass( config, accessor, baseType); typeSer = b.buildTypeSerializer(config, baseType, subtypes); } return typeSer; }
/** * Method called to create a type information serializer for values of given * container property * if one is needed. If not needed (no polymorphic handling configured), should * return null. * * @param containerType Declared type of the container to use as the base type for type information serializer * * @return Type serializer to use for property value contents, if one is needed; null if not. */ public TypeSerializer findPropertyContentTypeSerializer(JavaType containerType, SerializationConfig config, AnnotatedMember accessor) throws JsonMappingException { JavaType contentType = containerType.getContentType(); AnnotationIntrospector ai = config.getAnnotationIntrospector(); TypeResolverBuilder<?> b = ai.findPropertyContentTypeResolver(config, accessor, containerType); TypeSerializer typeSer; // Defaulting: if no annotations on member, check value class if (b == null) { typeSer = createTypeSerializer(config, contentType); } else { Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config, accessor, contentType); typeSer = b.buildTypeSerializer(config, contentType, subtypes); } return typeSer; }
private void setupJackson(Injector injector, final ObjectMapper mapper) { final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector(); mapper.setInjectableValues(new GuiceInjectableValues(injector)); mapper.setAnnotationIntrospectors( new AnnotationIntrospectorPair(guiceIntrospector, mapper.getSerializationConfig().getAnnotationIntrospector()), new AnnotationIntrospectorPair(guiceIntrospector, mapper.getDeserializationConfig().getAnnotationIntrospector()) ); } }
/** * Method called to construct a type serializer for values with given declared * base type. This is called for values other than those of bean property * types. */ @Override public TypeSerializer createTypeSerializer(SerializationConfig config, JavaType baseType) { BeanDescription bean = config.introspectClassAnnotations(baseType.getRawClass()); AnnotatedClass ac = bean.getClassInfo(); AnnotationIntrospector ai = config.getAnnotationIntrospector(); TypeResolverBuilder<?> b = ai.findTypeResolver(config, ac, baseType); /* Ok: if there is no explicit type info handler, we may want to * use a default. If so, config object knows what to use. */ Collection<NamedType> subtypes = null; if (b == null) { b = config.getDefaultTyper(baseType); } else { subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config, ac); } if (b == null) { return null; } // 10-Jun-2015, tatu: Since not created for Bean Property, no need for post-processing // wrt EXTERNAL_PROPERTY return b.buildTypeSerializer(config, baseType, subtypes); }
private static ObjectMapper setupInjectablesInObjectMapper(ObjectMapper objectMapper) { final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector(); objectMapper.setAnnotationIntrospectors( new AnnotationIntrospectorPair( guiceIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector() ), new AnnotationIntrospectorPair( guiceIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector() ) ); GuiceInjectableValues injectableValues = new GuiceInjectableValues( GuiceInjectors.makeStartupInjectorWithModules( ImmutableList.of( binder -> { binder.bind(AuthorizerMapper.class).toInstance(AuthTestUtils.TEST_AUTHORIZER_MAPPER); binder.bind(ChatHandlerProvider.class).toInstance(new NoopChatHandlerProvider()); binder.bind(RowIngestionMetersFactory.class).toInstance(rowIngestionMetersFactory); } ) ) ); objectMapper.setInjectableValues(injectableValues); objectMapper.registerModule( new SimpleModule().registerSubtypes(new NamedType(NumberedShardSpec.class, "NumberedShardSpec")) ); return objectMapper; }
public PropertyBuilder(SerializationConfig config, BeanDescription beanDesc) { _config = config; _beanDesc = beanDesc; // 08-Sep-2016, tatu: This gets tricky, with 3 levels of definitions: // (a) global default inclusion // (b) per-type default inclusion (from annotation or config overrides; // config override having precedence) // (c) per-property override (from annotation on specific property or // config overrides per type of property; // annotation having precedence) // // and not only requiring merging, but also considering special handling // for NON_DEFAULT in case of (b) (vs (a) or (c)) JsonInclude.Value inclPerType = JsonInclude.Value.merge( beanDesc.findPropertyInclusion(JsonInclude.Value.empty()), config.getDefaultPropertyInclusion(beanDesc.getBeanClass(), JsonInclude.Value.empty())); _defaultInclusion = JsonInclude.Value.merge(config.getDefaultPropertyInclusion(), inclPerType); _useRealPropertyDefaults = inclPerType.getValueInclusion() == JsonInclude.Include.NON_DEFAULT; _annotationIntrospector = _config.getAnnotationIntrospector(); }
new AnnotationIntrospectorPair( guiceIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector() ), new AnnotationIntrospectorPair(
@BeforeClass public static void setUp() { final Injector injector = GuiceInjectors.makeStartupInjectorWithModules( ImmutableList.of( new Module() { @Override public void configure(Binder binder) { binder.bind(LocalDataSegmentPuller.class); } } ) ); mapper = new DefaultObjectMapper(); mapper.registerModule(new SimpleModule("loadSpecTest").registerSubtypes(LocalLoadSpec.class)); mapper.setInjectableValues(new GuiceInjectableValues(injector)); final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector(); mapper.setAnnotationIntrospectors( new AnnotationIntrospectorPair(guiceIntrospector, mapper.getSerializationConfig().getAnnotationIntrospector()), new AnnotationIntrospectorPair(guiceIntrospector, mapper.getDeserializationConfig().getAnnotationIntrospector()) ); }
assertSame(deserializer, deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null)); assertSame(annotationIntrospector, mapper.getSerializationConfig().getAnnotationIntrospector()); assertSame(annotationIntrospector, mapper.getDeserializationConfig().getAnnotationIntrospector());
assertNull(serializers.findSerializer(null, SimpleType.construct(Number.class), null)); assertSame(annotationIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector()); assertSame(annotationIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector());
final AnnotationIntrospector intr = config.getAnnotationIntrospector(); JavaType type;
@Override public JsonSerializer<?> findMapLikeSerializer(SerializationConfig config, MapLikeType type, BeanDescription beanDesc, JsonSerializer<Object> keySerializer, TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) { if (Multimap.class.isAssignableFrom(type.getRawClass())) { final AnnotationIntrospector intr = config.getAnnotationIntrospector(); Object filterId = intr.findFilterId((Annotated)beanDesc.getClassInfo()); JsonIgnoreProperties.Value ignorals = config.getDefaultPropertyIgnorals(Multimap.class, beanDesc.getClassInfo()); Set<String> ignored = (ignorals == null) ? null : ignorals.getIgnored(); return new MultimapSerializer(type, beanDesc, keySerializer, elementTypeSerializer, elementValueSerializer, ignored, filterId); } return null; }
@Override protected JsonEndpointConfig _configForWriting(final ObjectMapper mapper, final Annotation[] annotations, final Class<?> defaultView) { final AnnotationIntrospector customIntrospector = mapper.getSerializationConfig().getAnnotationIntrospector(); // Set the custom (user) introspector to be the primary one. final ObjectMapper filteringMapper = mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(customIntrospector, new JacksonAnnotationIntrospector() { @Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } })); return super._configForWriting(filteringMapper, annotations, defaultView); }