bbeaudreault commented on code in PR #4937:
URL: https://github.com/apache/hbase/pull/4937#discussion_r1085671686


##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/OnlineLogRecord.java:
##########
@@ -36,13 +43,31 @@
 @InterfaceStability.Evolving
 final public class OnlineLogRecord extends LogEntry {
 
-  // used to convert object to pretty printed format
-  // used by toJsonPrettyPrint()
+  private static final Logger LOG = 
LoggerFactory.getLogger(OnlineLogRecord.class.getName());
+  private static final JsonElement EXCLUDED_NODE = 
JsonParser.parseString(HConstants.EMPTY_STRING);
+
+  private static JsonElement serializeCatchAll(Operation operation) {
+    try {
+      return JsonParser.parseString(operation.toJSON());
+    } catch (Exception e) {
+      LOG.warn("Suppressing exception during OnlineLogRecord serialization 
with operation {}",
+        operation, e);
+      return EXCLUDED_NODE;
+    }
+  }
+
+  private static final Gson INNER_GSON = 
GsonUtil.createGson().setPrettyPrinting()
+    .registerTypeAdapter(Operation.class,
+      (JsonSerializer<
+        Operation>) (operation, type, jsonSerializationContext) -> 
serializeCatchAll(operation))
+    .registerTypeAdapter(Optional.class,
+      (JsonSerializer<Optional<?>>) (optional, type, jsonSerializationContext) 
-> optional
+        .map(jsonSerializationContext::serialize).orElse(EXCLUDED_NODE))
+    .create();
   private static final Gson GSON =
     
GsonUtil.createGson().setPrettyPrinting().registerTypeAdapter(OnlineLogRecord.class,
       (JsonSerializer<OnlineLogRecord>) (slowLogPayload, type, 
jsonSerializationContext) -> {
-        Gson gson = new Gson();
-        JsonObject jsonObj = (JsonObject) gson.toJsonTree(slowLogPayload);
+        JsonObject jsonObj = (JsonObject) 
INNER_GSON.toJsonTree(slowLogPayload);

Review Comment:
   did you try doing `jsonSerliazationContext.serialize(slowPayLoad)`? I feel 
like that's the appropriate call which should hopefully work with chaining, but 
not sure.  



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to