com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector Java Examples
The following examples show how to use
com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector.
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: IssueTrackerConfiguration.java From spring-data-dev-tools with Apache License 2.0 | 6 votes |
@Override public void setupModule(SetupContext context) { context.insertAnnotationIntrospector(new NopAnnotationIntrospector() { private static final long serialVersionUID = 479313244908256455L; @Override public boolean hasIgnoreMarker(AnnotatedMember m) { if (!(m instanceof AnnotatedMethod)) { return super.hasIgnoreMarker(m); } AnnotatedMethod method = (AnnotatedMethod) m; return method.getName().startsWith("lambda$") ? true : super.hasIgnoreMarker(m); } }); }
Example #2
Source File: MapperConfig.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Method for getting {@link AnnotationIntrospector} configured * to introspect annotation values used for configuration. *<p> * Non-final since it is actually overridden by sub-classes (for now?) */ public AnnotationIntrospector getAnnotationIntrospector() { if (isEnabled(MapperFeature.USE_ANNOTATIONS)) { return _base.getAnnotationIntrospector(); } return NopAnnotationIntrospector.instance; }
Example #3
Source File: Jackson2ObjectMapperFactoryBeanTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void completeSetup() { NopAnnotationIntrospector annotationIntrospector = NopAnnotationIntrospector.instance; ObjectMapper objectMapper = new ObjectMapper(); this.factory.setObjectMapper(objectMapper); assertTrue(this.factory.isSingleton()); assertEquals(ObjectMapper.class, this.factory.getObjectType()); Map<Class<?>, JsonDeserializer<?>> deserializers = new HashMap<>(); deserializers.put(Date.class, new DateDeserializer()); JsonSerializer<Class<?>> serializer1 = new ClassSerializer(); JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class); // Disable well-known modules detection this.factory.setModules(new ArrayList<>()); this.factory.setSerializers(serializer1); this.factory.setSerializersByType(Collections.singletonMap(Boolean.class, serializer2)); this.factory.setDeserializersByType(deserializers); this.factory.setAnnotationIntrospector(annotationIntrospector); this.factory.setFeaturesToEnable(SerializationFeature.FAIL_ON_EMPTY_BEANS, DeserializationFeature.UNWRAP_ROOT_VALUE, JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS); this.factory.setFeaturesToDisable(MapperFeature.AUTO_DETECT_GETTERS, MapperFeature.AUTO_DETECT_FIELDS, JsonParser.Feature.AUTO_CLOSE_SOURCE, JsonGenerator.Feature.QUOTE_FIELD_NAMES); assertFalse(getSerializerFactoryConfig(objectMapper).hasSerializers()); assertFalse(getDeserializerFactoryConfig(objectMapper).hasDeserializers()); this.factory.setSerializationInclusion(Include.NON_NULL); this.factory.afterPropertiesSet(); assertSame(objectMapper, this.factory.getObject()); assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers()); assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers()); Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next(); assertSame(serializer1, serializers.findSerializer(null, SimpleType.construct(Class.class), null)); assertSame(serializer2, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null)); assertNull(serializers.findSerializer(null, SimpleType.construct(Number.class), null)); assertSame(annotationIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector()); assertSame(annotationIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector()); assertTrue(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS)); assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE)); assertTrue(objectMapper.getFactory().isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)); assertTrue(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS)); assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS)); assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)); assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS)); assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)); assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES)); assertSame(Include.NON_NULL, objectMapper.getSerializationConfig().getSerializationInclusion()); }
Example #4
Source File: Jackson2ObjectMapperFactoryBeanTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void completeSetup() { NopAnnotationIntrospector annotationIntrospector = NopAnnotationIntrospector.instance; ObjectMapper objectMapper = new ObjectMapper(); this.factory.setObjectMapper(objectMapper); assertTrue(this.factory.isSingleton()); assertEquals(ObjectMapper.class, this.factory.getObjectType()); Map<Class<?>, JsonDeserializer<?>> deserializers = new HashMap<>(); deserializers.put(Date.class, new DateDeserializer()); JsonSerializer<Class<?>> serializer1 = new ClassSerializer(); JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class); // Disable well-known modules detection this.factory.setModules(new ArrayList<>()); this.factory.setSerializers(serializer1); this.factory.setSerializersByType(Collections.singletonMap(Boolean.class, serializer2)); this.factory.setDeserializersByType(deserializers); this.factory.setAnnotationIntrospector(annotationIntrospector); this.factory.setFeaturesToEnable(SerializationFeature.FAIL_ON_EMPTY_BEANS, DeserializationFeature.UNWRAP_ROOT_VALUE, JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS); this.factory.setFeaturesToDisable(MapperFeature.AUTO_DETECT_GETTERS, MapperFeature.AUTO_DETECT_FIELDS, JsonParser.Feature.AUTO_CLOSE_SOURCE, JsonGenerator.Feature.QUOTE_FIELD_NAMES); assertFalse(getSerializerFactoryConfig(objectMapper).hasSerializers()); assertFalse(getDeserializerFactoryConfig(objectMapper).hasDeserializers()); this.factory.setSerializationInclusion(Include.NON_NULL); this.factory.afterPropertiesSet(); assertSame(objectMapper, this.factory.getObject()); assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers()); assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers()); Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next(); assertSame(serializer1, serializers.findSerializer(null, SimpleType.construct(Class.class), null)); assertSame(serializer2, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null)); assertNull(serializers.findSerializer(null, SimpleType.construct(Number.class), null)); assertSame(annotationIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector()); assertSame(annotationIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector()); assertTrue(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS)); assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE)); assertTrue(objectMapper.getFactory().isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)); assertTrue(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS)); assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS)); assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)); assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS)); assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)); assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES)); assertSame(Include.NON_NULL, objectMapper.getSerializationConfig().getSerializationInclusion()); }
Example #5
Source File: Jackson2ObjectMapperFactoryBeanTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void completeSetup() { NopAnnotationIntrospector annotationIntrospector = NopAnnotationIntrospector.instance; ObjectMapper objectMapper = new ObjectMapper(); this.factory.setObjectMapper(objectMapper); assertTrue(this.factory.isSingleton()); assertEquals(ObjectMapper.class, this.factory.getObjectType()); Map<Class<?>, JsonDeserializer<?>> deserializers = new HashMap<Class<?>, JsonDeserializer<?>>(); deserializers.put(Date.class, new DateDeserializer()); JsonSerializer<Class<?>> serializer1 = new ClassSerializer(); JsonSerializer<Number> serializer2 = new NumberSerializer(Integer.class); // Disable well-known modules detection this.factory.setModules(new ArrayList<>()); this.factory.setSerializers(serializer1); this.factory.setSerializersByType(Collections.singletonMap(Boolean.class, serializer2)); this.factory.setDeserializersByType(deserializers); this.factory.setAnnotationIntrospector(annotationIntrospector); this.factory.setFeaturesToEnable(SerializationFeature.FAIL_ON_EMPTY_BEANS, DeserializationFeature.UNWRAP_ROOT_VALUE, JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS); this.factory.setFeaturesToDisable(MapperFeature.AUTO_DETECT_GETTERS, MapperFeature.AUTO_DETECT_FIELDS, JsonParser.Feature.AUTO_CLOSE_SOURCE, JsonGenerator.Feature.QUOTE_FIELD_NAMES); assertFalse(getSerializerFactoryConfig(objectMapper).hasSerializers()); assertFalse(getDeserializerFactoryConfig(objectMapper).hasDeserializers()); this.factory.setSerializationInclusion(Include.NON_NULL); this.factory.afterPropertiesSet(); assertSame(objectMapper, this.factory.getObject()); assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers()); assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers()); Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next(); assertSame(serializer1, serializers.findSerializer(null, SimpleType.construct(Class.class), null)); assertSame(serializer2, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null)); assertNull(serializers.findSerializer(null, SimpleType.construct(Number.class), null)); assertSame(annotationIntrospector, objectMapper.getSerializationConfig().getAnnotationIntrospector()); assertSame(annotationIntrospector, objectMapper.getDeserializationConfig().getAnnotationIntrospector()); assertTrue(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS)); assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE)); assertTrue(objectMapper.getFactory().isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)); assertTrue(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS)); assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS)); assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)); assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS)); assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)); assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES)); assertSame(Include.NON_NULL, objectMapper.getSerializationConfig().getSerializationInclusion()); }