I am are using cloud logging APIs to publish stackdriver logs. I'm trying to log a java object . I'm using an enhancer to convert a textpayload to jsonPayload. I don't see any errors while I convert the payload. However, I see that only the values which are null are being logged. Non null values are not logged as part of the jsonPayload.
converting the object to a JsonString
logger.info(mapper.writeValueAsString(pd));
code in the logging enhancer
@Override
public void enhanceLogEntry(LogEntry.Builder logEntry) {
logEntry.addLabel("project", "test");
// Transform textPayload to JSONPayload
ObjectMapper mapper = new ObjectMapper();
Builder structBuilder = Struct.newBuilder();
String textPayload = logEntry.build().getPayload().getData().toString();
try {
mapper.readTree(textPayload);
JsonFormat.parser().merge(textPayload, structBuilder);
logEntry.setPayload(JsonPayload.of(structBuilder.build()));
} catch (InvalidProtocolBufferException e) {
System.err.println(e.getMessage());
} catch (IOException e) {
// Do nothing (there is not a JSON Payload)
}
}