aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatu Saloranta <tatu.saloranta@iki.fi>2020-04-16 14:31:05 -0700
committerTatu Saloranta <tatu.saloranta@iki.fi>2020-04-16 14:31:05 -0700
commitbce734f89db09a6b4e3290db9a80cae2f055b29f (patch)
tree60410ca14676d8e1ab05e958b1bfde2ec4888278
parentd26757f1367ee3b87a77a01a930447c5ebaa6ef0 (diff)
downloadjackson-annotations-bce734f89db09a6b4e3290db9a80cae2f055b29f.tar.gz
Minor improvement to `null` handling (avoidance) for `JsonPattern.Value`
-rw-r--r--release-notes/VERSION-2.x3
-rw-r--r--src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java12
-rw-r--r--src/test/java/com/fasterxml/jackson/annotation/FormatTest.java2
3 files changed, 9 insertions, 8 deletions
diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x
index adf7466..c9ab66f 100644
--- a/release-notes/VERSION-2.x
+++ b/release-notes/VERSION-2.x
@@ -13,7 +13,8 @@ NOTE: Annotations module will never contain changes in patch versions,
2.11.0 (not yet released)
-No changes since 2.10
+- `JsonPattern.Value.pattern` retained as "", never (accidentally) exposed
+ as `null`
2.10.0 (26-Sep-2019)
diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java b/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
index 5064727..5c9daef 100644
--- a/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
+++ b/src/main/java/com/fasterxml/jackson/annotation/JsonFormat.java
@@ -486,7 +486,7 @@ public @interface JsonFormat
public Value(String p, Shape sh, Locale l, TimeZone tz, Features f,
Boolean lenient)
{
- _pattern = p;
+ _pattern = (p == null) ? "" : p;
_shape = (sh == null) ? Shape.ANY : sh;
_locale = l;
_timezone = tz;
@@ -501,7 +501,7 @@ public @interface JsonFormat
public Value(String p, Shape sh, Locale l, String tzStr, TimeZone tz, Features f,
Boolean lenient)
{
- _pattern = p;
+ _pattern = (p == null) ? "" : p;
_shape = (sh == null) ? Shape.ANY : sh;
_locale = l;
_timezone = tz;
@@ -561,7 +561,7 @@ public @interface JsonFormat
}
return result;
}
-
+
/**
* @since 2.7
*/
@@ -626,17 +626,17 @@ public @interface JsonFormat
* @since 2.7
*/
public static Value forShape(Shape sh) {
- return new Value(null, sh, null, null, null, Features.empty(), null);
+ return new Value("", sh, null, null, null, Features.empty(), null);
}
/**
* @since 2.9
*/
public static Value forLeniency(boolean lenient) {
- return new Value(null, null, null, null, null, Features.empty(),
+ return new Value("", null, null, null, null, Features.empty(),
Boolean.valueOf(lenient));
}
-
+
/**
* @since 2.1
*/
diff --git a/src/test/java/com/fasterxml/jackson/annotation/FormatTest.java b/src/test/java/com/fasterxml/jackson/annotation/FormatTest.java
index bfe5389..8c0f873 100644
--- a/src/test/java/com/fasterxml/jackson/annotation/FormatTest.java
+++ b/src/test/java/com/fasterxml/jackson/annotation/FormatTest.java
@@ -55,7 +55,7 @@ public class FormatTest extends TestBase
}
public void testToString() {
- assertEquals("JsonFormat.Value(pattern=null,shape=STRING,lenient=null,locale=null,timezone=null,features=EMPTY)",
+ assertEquals("JsonFormat.Value(pattern=,shape=STRING,lenient=null,locale=null,timezone=null,features=EMPTY)",
JsonFormat.Value.forShape(JsonFormat.Shape.STRING).toString());
assertEquals("JsonFormat.Value(pattern=[.],shape=ANY,lenient=null,locale=null,timezone=null,features=EMPTY)",
JsonFormat.Value.forPattern("[.]").toString());