-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demo-jetty: custom converter example
- Loading branch information
Showing
4 changed files
with
38 additions
and
2 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
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
27 changes: 27 additions & 0 deletions
27
demo-jetty/src/main/java/net/cactusthorn/routing/demo/jetty/LocalDateConverter.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,27 @@ | ||
package net.cactusthorn.routing.demo.jetty; | ||
|
||
import net.cactusthorn.routing.RequestData; | ||
import net.cactusthorn.routing.convert.Converter; | ||
import net.cactusthorn.routing.convert.ConverterException; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
public class LocalDateConverter implements Converter { | ||
|
||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("ddMMyyyy"); | ||
|
||
@Override // | ||
public LocalDate convert(RequestData requestData, Class<?> type, String value) throws ConverterException { | ||
if (value == null || value.trim().isEmpty()) { | ||
return null; | ||
} | ||
try { | ||
return LocalDate.parse(value, FORMATTER); | ||
} catch (DateTimeParseException e) { | ||
throw new ConverterException("LocalDate converting failed", e); | ||
} | ||
} | ||
|
||
} |
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