Skip to content

Commit

Permalink
Revert "use add-opens to allow serialization of java.time.Duration"
Browse files Browse the repository at this point in the history
This reverts commit d1feef2.
  • Loading branch information
diegomarquezp committed Nov 22, 2024
1 parent 2b09a03 commit 46b9172
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.logging.v2.LogEntrySourceLocation;
import com.google.logging.v2.LogName;
import java.io.Serializable;
import java.time.Duration;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -612,6 +613,14 @@ public JsonElement serialize(
}
}

static final class DurationSerializer implements JsonSerializer<Duration> {
@Override
public JsonElement serialize(
Duration src, java.lang.reflect.Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.toString());
}
}

static final class SourceLocationSerializer implements JsonSerializer<SourceLocation> {
@Override
public JsonElement serialize(
Expand Down Expand Up @@ -649,6 +658,7 @@ public StructuredLogFormatter(StringBuilder builder) {
checkNotNull(builder);
this.gson =
new GsonBuilder()
.registerTypeAdapter(Duration.class, new DurationSerializer())
.registerTypeAdapter(Instant.class, new InstantSerializer())
.registerTypeAdapter(SourceLocation.class, new SourceLocationSerializer())
.registerTypeAdapter(HttpRequest.RequestMethod.class, new RequestMethodSerializer())
Expand Down
32 changes: 0 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,38 +197,6 @@
<ignoredUnusedDeclaredDependencies>org.objenesis:objenesis</ignoredUnusedDeclaredDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifestEntries>
<!-- This manifest entry is ignored by java 8.
It allows inter-module access when Gson serializes
the private variables of java.time.Duration -->
<Add-Opens>java.base/java.time=ALL-UNNAMED</Add-Opens>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- This arg line allows inter-module access when Gson serializes
the private variables of java.time.Duration -->
<argLine>--add-opens java.base/java.time=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down

0 comments on commit 46b9172

Please sign in to comment.