[
https://issues.apache.org/jira/browse/GROOVY-12010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18081055#comment-18081055
]
ASF GitHub Bot commented on GROOVY-12010:
-----------------------------------------
Copilot commented on code in PR #2535:
URL: https://github.com/apache/groovy/pull/2535#discussion_r3245940332
##########
subprojects/groovy-toml/src/main/java/groovy/toml/TomlSlurper.java:
##########
@@ -126,12 +129,20 @@ public <T> T parseTextAs(Class<T> type, String toml) {
*/
public <T> T parseAs(Class<T> type, Reader reader) {
try {
- return new TomlMapper().readValue(reader, type);
+ return mapper().readValue(reader, type);
} catch (IOException e) {
throw new TomlRuntimeException(e);
}
}
+ static TomlMapper mapper() {
+ return TomlMapper.builder()
+ .addModule(new JavaTimeModule())
+ .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
+
.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
+ .build();
Review Comment:
`mapper()` builds a new `TomlMapper` (and `JavaTimeModule`) on every call.
Since `ObjectMapper`/`TomlMapper` is thread-safe after configuration, this
should be cached (e.g., a `private static final TomlMapper` initialized once)
to avoid repeated allocation/configuration in `parseAs` and
`TomlBuilder.toToml` hot paths.
##########
subprojects/groovy-toml/src/spec/test/groovy/toml/TomlParserTest.groovy:
##########
@@ -163,4 +163,55 @@ port = 8080
def config = new TomlSlurper().parseAs(ServerConfig, stream)
assert config.port == 3000
}
+
+ // tag::temporal_class[]
+ static class Event {
+ java.time.OffsetDateTime created
+ java.time.LocalDate effective
+ java.time.LocalTime windowStart
+ String name
Review Comment:
The user guide claims typed parsing supports `java.time.LocalDateTime`, but
the new round-trip test only covers `OffsetDateTime`, `LocalDate`, and
`LocalTime`. Add a `LocalDateTime` field to `Event` and assert it round-trips
too, so the documented behavior is pinned by tests.
> Graduate groovy-toml from incubating to stable
> ----------------------------------------------
>
> Key: GROOVY-12010
> URL: https://issues.apache.org/jira/browse/GROOVY-12010
> Project: Groovy
> Issue Type: Improvement
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
> Fix For: 6.0.0-alpha-2
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)