-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to deserialize an empty string to null #630
Conversation
@@ -292,6 +292,17 @@ private Boolean decodeBooleanSlow() throws IOException { | |||
return null; | |||
} | |||
case START_OBJECT, END_OBJECT, END_ARRAY, FIELD_NAME -> throw unexpectedToken(JsonToken.VALUE_TRUE, t); | |||
case VALUE_STRING -> { | |||
String string = parser.getText(); | |||
if (string.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use?
if (string.isEmpty()) { | |
if (StringUtils.isEmpty(string)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
@@ -312,6 +323,17 @@ public byte decodeByte() throws IOException { | |||
public Byte decodeByteNullable() throws IOException { | |||
JsonToken t = nextToken(); | |||
switch (t) { | |||
case VALUE_STRING -> { | |||
String string = parser.getText(); | |||
if (string.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (string.isEmpty()) { | |
if (StringUtils.isEmpty(string)) { |
@@ -353,6 +375,17 @@ public short decodeShort() throws IOException { | |||
public Short decodeShortNullable() throws IOException { | |||
JsonToken t = nextToken(); | |||
switch (t) { | |||
case VALUE_STRING -> { | |||
String string = parser.getText(); | |||
if (string.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (string.isEmpty()) { | |
if (StringUtils.isEmpty(string)) { |
@@ -407,6 +440,9 @@ public Character decodeCharNullable() throws IOException { | |||
} | |||
case VALUE_STRING -> { | |||
String string = parser.getText(); | |||
if (string.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (string.isEmpty()) { | |
if (StringUtils.isEmpty(string)) { |
@@ -460,6 +496,9 @@ private Integer decodeIntSlow() throws IOException { | |||
} | |||
case VALUE_STRING -> { | |||
String string = parser.getText(); | |||
if (string.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (string.isEmpty()) { | |
if (StringUtils.isEmpty(string)) { |
@@ -579,13 +619,14 @@ public Float decodeFloatNullable() throws IOException { | |||
switch (t) { | |||
case VALUE_STRING -> { | |||
String string = parser.getText(); | |||
float value; | |||
if (string.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (string.isEmpty()) { | |
if (StringUtils.isEmpty(string)) { |
@@ -641,6 +682,9 @@ private Double decodeDoubleSlow(JsonToken t) throws IOException { | |||
} | |||
case VALUE_STRING -> { | |||
String string = parser.getText(); | |||
if (string.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (string.isEmpty()) { | |
if (StringUtils.isEmpty(string)) { |
@@ -691,6 +735,9 @@ public BigInteger decodeBigIntegerNullable() throws IOException { | |||
switch (t) { | |||
case VALUE_STRING -> { | |||
String string = parser.getText(); | |||
if (string.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (string.isEmpty()) { | |
if (StringUtils.isEmpty(string)) { |
@@ -741,6 +788,9 @@ public BigDecimal decodeBigDecimalNullable() throws IOException { | |||
switch (t) { | |||
case VALUE_STRING -> { | |||
String string = parser.getText(); | |||
if (string.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (string.isEmpty()) { | |
if (StringUtils.isEmpty(string)) { |
@@ -793,7 +843,8 @@ private Number decodeNumber() throws IOException { | |||
|
|||
@Override | |||
public boolean decodeNull() throws IOException { | |||
if (peekToken() == JsonToken.VALUE_NULL) { | |||
JsonToken jsonToken = peekToken(); | |||
if (jsonToken == JsonToken.VALUE_NULL || jsonToken == JsonToken.VALUE_STRING && parser.getText().isBlank()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (jsonToken == JsonToken.VALUE_NULL || jsonToken == JsonToken.VALUE_STRING && parser.getText().isBlank()) { | |
if (jsonToken == JsonToken.VALUE_NULL || jsonToken == JsonToken.VALUE_STRING && StringUtils.isEmpty(parser.getText())) { |
I think that utility method is needed |
why on earth does JacksonDecoder matter for forms? |
To convert forms into a bean, we convert a map into the JSON node model in |
SonarCloud Quality Gate failed. 0 Bugs 79.6% Coverage Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
Not sure if this is the best solution. Maybe it should be configurable?
Fixes #619