From 36f718833487a5fa26a69840782e53d7c7e831ff Mon Sep 17 00:00:00 2001 From: fidel Date: Sat, 2 Mar 2019 17:21:20 +0900 Subject: [PATCH 1/2] Permit use of @JsonTest without Jackson See gh-16070 --- .../boot/test/autoconfigure/json/JsonExcludeFilter.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonExcludeFilter.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonExcludeFilter.java index 6bbb15fcc1..74d8c525fe 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonExcludeFilter.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonExcludeFilter.java @@ -20,13 +20,12 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; -import com.fasterxml.jackson.databind.Module; - import org.springframework.boot.context.TypeExcludeFilter; import org.springframework.boot.jackson.JsonComponent; import org.springframework.boot.test.autoconfigure.filter.AnnotationCustomizableTypeExcludeFilter; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.util.ClassUtils; /** * {@link TypeExcludeFilter} for {@link JsonTest @JsonTest}. @@ -39,8 +38,12 @@ class JsonExcludeFilter extends AnnotationCustomizableTypeExcludeFilter { static { Set> includes = new LinkedHashSet>(); - includes.add(Module.class); includes.add(JsonComponent.class); + try { + includes.add(ClassUtils.forName("com.fasterxml.jackson.databind.Module", null)); + } catch (Exception ex) { + // Ignore + } DEFAULT_INCLUDES = Collections.unmodifiableSet(includes); }; From 329a6905d88371235f11bd3d0cd3ccbdefb9fe27 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 4 Mar 2019 14:48:39 +0100 Subject: [PATCH 2/2] Polish "Permit use of @JsonTest without Jackson" Closes gh-16070 --- .../test/autoconfigure/json/JsonExcludeFilter.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonExcludeFilter.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonExcludeFilter.java index 74d8c525fe..de86425971 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonExcludeFilter.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonExcludeFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,18 +34,20 @@ import org.springframework.util.ClassUtils; */ class JsonExcludeFilter extends AnnotationCustomizableTypeExcludeFilter { + private static final String JACKSON_MODULE = "com.fasterxml.jackson.databind.Module"; + private static final Set> DEFAULT_INCLUDES; static { Set> includes = new LinkedHashSet>(); - includes.add(JsonComponent.class); try { - includes.add(ClassUtils.forName("com.fasterxml.jackson.databind.Module", null)); - } catch (Exception ex) { - // Ignore + includes.add(ClassUtils.forName(JACKSON_MODULE, null)); + } + catch (Exception ex) { } + includes.add(JsonComponent.class); DEFAULT_INCLUDES = Collections.unmodifiableSet(includes); - }; + } private final JsonTest annotation;