File tree Expand file tree Collapse file tree 2 files changed +10
-32
lines changed
google-cloud-logging/src/main/java/com/google/cloud/logging Expand file tree Collapse file tree 2 files changed +10
-32
lines changed Original file line number Diff line number Diff line change 3434import com .google .logging .v2 .LogEntrySourceLocation ;
3535import com .google .logging .v2 .LogName ;
3636import java .io .Serializable ;
37+ import java .time .Duration ;
3738import java .time .Instant ;
3839import java .util .HashMap ;
3940import 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 ())
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments