From 770f6786c22aca7921e30725aeb5bbcb38eb0077 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 7 May 2019 02:03:11 +0200 Subject: [PATCH] Polishing --- .../util/PatternMatchUtils.java | 9 ++++++--- .../json/Jackson2ObjectMapperBuilder.java | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/PatternMatchUtils.java b/spring-core/src/main/java/org/springframework/util/PatternMatchUtils.java index d608dba981..583dc8eb0a 100644 --- a/spring-core/src/main/java/org/springframework/util/PatternMatchUtils.java +++ b/spring-core/src/main/java/org/springframework/util/PatternMatchUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-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. @@ -37,20 +37,22 @@ public abstract class PatternMatchUtils { if (pattern == null || str == null) { return false; } + int firstIndex = pattern.indexOf('*'); if (firstIndex == -1) { return pattern.equals(str); } + if (firstIndex == 0) { if (pattern.length() == 1) { return true; } - int nextIndex = pattern.indexOf('*', firstIndex + 1); + int nextIndex = pattern.indexOf('*', 1); if (nextIndex == -1) { return str.endsWith(pattern.substring(1)); } String part = pattern.substring(1, nextIndex); - if ("".equals(part)) { + if (part.isEmpty()) { return simpleMatch(pattern.substring(nextIndex), str); } int partIndex = str.indexOf(part); @@ -62,6 +64,7 @@ public abstract class PatternMatchUtils { } return false; } + return (str.length() >= firstIndex && pattern.substring(0, firstIndex).equals(str.substring(0, firstIndex)) && simpleMatch(pattern.substring(firstIndex), str.substring(firstIndex))); diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java index b0b0286303..acde2b84a9 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java @@ -260,7 +260,7 @@ public class Jackson2ObjectMapperBuilder { * @param mixinSource class (or interface) whose annotations are to be "added" * to target's annotations as value * @since 4.1.2 - * @see com.fasterxml.jackson.databind.ObjectMapper#addMixInAnnotations(Class, Class) + * @see com.fasterxml.jackson.databind.ObjectMapper#addMixIn(Class, Class) */ public Jackson2ObjectMapperBuilder mixIn(Class target, Class mixinSource) { if (mixinSource != null) { @@ -271,11 +271,11 @@ public class Jackson2ObjectMapperBuilder { /** * Add mix-in annotations to use for augmenting specified class or interface. - * @param mixIns Map of entries with target classes (or interface) whose annotations + * @param mixIns a Map of entries with target classes (or interface) whose annotations * to effectively override as key and mix-in classes (or interface) whose * annotations are to be "added" to target's annotations as value. * @since 4.1.2 - * @see com.fasterxml.jackson.databind.ObjectMapper#addMixInAnnotations(Class, Class) + * @see com.fasterxml.jackson.databind.ObjectMapper#addMixIn(Class, Class) */ public Jackson2ObjectMapperBuilder mixIns(Map, Class> mixIns) { if (mixIns != null) { @@ -304,8 +304,8 @@ public class Jackson2ObjectMapperBuilder { /** * Configure a custom serializer for the given type. - * @see #serializers(JsonSerializer...) * @since 4.1.2 + * @see #serializers(JsonSerializer...) */ public Jackson2ObjectMapperBuilder serializerByType(Class type, JsonSerializer serializer) { if (serializer != null) { @@ -463,6 +463,8 @@ public class Jackson2ObjectMapperBuilder { /** * Specify one or more modules to be registered with the {@link ObjectMapper}. + * Multiple invocations are not additive, the last one defines the modules to + * register. *

Note: If this is set, no finding of modules is going to happen - not by * Jackson, and not by Spring either (see {@link #findModulesViaServiceLoader}). * As a consequence, specifying an empty list here will suppress any kind of @@ -478,6 +480,8 @@ public class Jackson2ObjectMapperBuilder { /** * Set a complete list of modules to be registered with the {@link ObjectMapper}. + * Multiple invocations are not additive, the last one defines the modules to + * register. *

Note: If this is set, no finding of modules is going to happen - not by * Jackson, and not by Spring either (see {@link #findModulesViaServiceLoader}). * As a consequence, specifying an empty list here will suppress any kind of @@ -495,6 +499,8 @@ public class Jackson2ObjectMapperBuilder { /** * Specify one or more modules to be registered with the {@link ObjectMapper}. + * Multiple invocations are not additive, the last one defines the modules + * to register. *

Modules specified here will be registered after * Spring's autodetection of JSR-310 and Joda-Time, or Jackson's * finding of modules (see {@link #findModulesViaServiceLoader}), @@ -511,7 +517,8 @@ public class Jackson2ObjectMapperBuilder { /** * Specify one or more modules by class to be registered with - * the {@link ObjectMapper}. + * the {@link ObjectMapper}. Multiple invocations are not additive, + * the last one defines the modules to register. *

Modules specified here will be registered after * Spring's autodetection of JSR-310 and Joda-Time, or Jackson's * finding of modules (see {@link #findModulesViaServiceLoader}), @@ -529,7 +536,7 @@ public class Jackson2ObjectMapperBuilder { /** * Set whether to let Jackson find available modules via the JDK ServiceLoader, - * based on META-INF metadata in the classpath. Requires Jackson 2.2 or higher. + * based on META-INF metadata in the classpath. *

If this mode is not set, Spring's Jackson2ObjectMapperBuilder itself * will try to find the JSR-310 and Joda-Time support modules on the classpath - * provided that Java 8 and Joda-Time themselves are available, respectively. -- GitLab