-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#13768] URI should be deserialized from empty string to null.
See FasterXML/jackson-databind#398, but we don't need this edge case handling, client sends empty selection as empty string, so this should be handled as null.
- Loading branch information
1 parent
943a6a1
commit 2978b17
Showing
4 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
api/src/main/java/org/smartbit4all/core/object/serialize/UriDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.smartbit4all.core.object.serialize; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
|
||
public class UriDeserializer extends JsonDeserializer<URI> { | ||
|
||
public static final UriDeserializer INSTANCE = | ||
new UriDeserializer(); | ||
|
||
private UriDeserializer() {} | ||
|
||
@Override | ||
public URI deserialize(JsonParser p, DeserializationContext ctxt) | ||
throws IOException, JsonProcessingException { | ||
String text = p.getValueAsString(); | ||
if (text != null) { | ||
if (text.length() == 0 || (text = text.trim()).length() == 0) { | ||
// we don't want to treat "" as a valid URI | ||
return null; | ||
} | ||
return URI.create(text); | ||
} | ||
return null; | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ject/zone/ZonedLocalDateDeserializer.java → ...serialize/ZonedLocalDateDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../zone/ZonedLocalDateTimeDeserializer.java → ...alize/ZonedLocalDateTimeDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters