generated from NOAA-OWP/owp-open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into github_296
- Loading branch information
Showing
18 changed files
with
302 additions
and
90 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
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
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
46 changes: 46 additions & 0 deletions
46
wres-reading/src/wres/reading/wrds/nwm/DateTimeDeserializer.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,46 @@ | ||
package wres.reading.wrds.nwm; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import wres.reading.ReaderUtilities; | ||
|
||
/** | ||
* Custom deserializer for a datetime string in the ISO8601 "basic" format with optional minutes and seconds. For | ||
* example: 20240830T12Z, 20240830T1200Z and 20240830T120000Z are all acceptable. | ||
* | ||
* @author James Brown | ||
*/ | ||
public class DateTimeDeserializer extends JsonDeserializer<Instant> | ||
{ | ||
@Override | ||
public Instant deserialize( JsonParser jp, DeserializationContext context ) | ||
throws IOException | ||
{ | ||
JsonNode node = jp.getCodec() | ||
.readTree( jp ); | ||
|
||
String time; | ||
|
||
// Parse the instant. | ||
if ( node.isTextual() ) | ||
{ | ||
time = node.asText(); | ||
} | ||
else | ||
{ | ||
throw new IOException( "Could not find a datetime field in the document, which is not allowed." ); | ||
} | ||
|
||
// Lenient formatting in the "basic" ISO8601 format, hours and seconds are optional | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( "yyyyMMdd'T'HH[mm[ss]]'Z'" ) | ||
.withZone( ReaderUtilities.UTC ); | ||
return formatter.parse( time, Instant::from ); | ||
} | ||
} |
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
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
Oops, something went wrong.