Skip to content

Commit 46b9172

Browse files
committed
Revert "use add-opens to allow serialization of java.time.Duration"
This reverts commit d1feef2.
1 parent 2b09a03 commit 46b9172

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.google.logging.v2.LogEntrySourceLocation;
3535
import com.google.logging.v2.LogName;
3636
import java.io.Serializable;
37+
import java.time.Duration;
3738
import java.time.Instant;
3839
import java.util.HashMap;
3940
import java.util.Map;
@@ -612,6 +613,14 @@ public JsonElement serialize(
612613
}
613614
}
614615

616+
static final class DurationSerializer implements JsonSerializer<Duration> {
617+
@Override
618+
public JsonElement serialize(
619+
Duration src, java.lang.reflect.Type typeOfSrc, JsonSerializationContext context) {
620+
return new JsonPrimitive(src.toString());
621+
}
622+
}
623+
615624
static final class SourceLocationSerializer implements JsonSerializer<SourceLocation> {
616625
@Override
617626
public JsonElement serialize(
@@ -649,6 +658,7 @@ public StructuredLogFormatter(StringBuilder builder) {
649658
checkNotNull(builder);
650659
this.gson =
651660
new GsonBuilder()
661+
.registerTypeAdapter(Duration.class, new DurationSerializer())
652662
.registerTypeAdapter(Instant.class, new InstantSerializer())
653663
.registerTypeAdapter(SourceLocation.class, new SourceLocationSerializer())
654664
.registerTypeAdapter(HttpRequest.RequestMethod.class, new RequestMethodSerializer())

pom.xml

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -197,38 +197,6 @@
197197
<ignoredUnusedDeclaredDependencies>org.objenesis:objenesis</ignoredUnusedDeclaredDependencies>
198198
</configuration>
199199
</plugin>
200-
<plugin>
201-
<groupId>org.apache.maven.plugins</groupId>
202-
<artifactId>maven-jar-plugin</artifactId>
203-
<executions>
204-
<execution>
205-
<id>default-jar</id>
206-
<phase>package</phase>
207-
<goals>
208-
<goal>jar</goal>
209-
</goals>
210-
<configuration>
211-
<archive>
212-
<manifestEntries>
213-
<!-- This manifest entry is ignored by java 8.
214-
It allows inter-module access when Gson serializes
215-
the private variables of java.time.Duration -->
216-
<Add-Opens>java.base/java.time=ALL-UNNAMED</Add-Opens>
217-
</manifestEntries>
218-
</archive>
219-
</configuration>
220-
</execution>
221-
</executions>
222-
</plugin>
223-
<plugin>
224-
<groupId>org.apache.maven.plugins</groupId>
225-
<artifactId>maven-surefire-plugin</artifactId>
226-
<configuration>
227-
<!-- This arg line allows inter-module access when Gson serializes
228-
the private variables of java.time.Duration -->
229-
<argLine>--add-opens java.base/java.time=ALL-UNNAMED</argLine>
230-
</configuration>
231-
</plugin>
232200
</plugins>
233201
</pluginManagement>
234202
</build>

0 commit comments

Comments
 (0)