/** * Creates a log entry payload given its JSON data represented as a map. The provided map is * copied into a {@link Struct} object. * * <p>Notice that all numbers (int, long, float and double) are serialized as double values. * Enums are serialized as strings. * * <p>Example usage of {@code JsonPayload}: * * <pre>{@code * List<Long> listValue = Arrays.asList(1L, 2L); * Map<String, Object> innerMap = new HashMap<String, Object>(); * innerMap.put("booleanValue", true); * innerMap.put("stringValue", "stringValue"); * Map<String, Object> jsonContent = new HashMap<String, Object>(); * jsonContent.put("listValue", listValue); * jsonContent.put("integerValue", 42); * jsonContent.put("doubleValue", 42.0); * jsonContent.put("stringValue", "stringValue"); * jsonContent.put("mapValue", innerMap); * JsonPayload payload = JsonPayload.of(jsonContent); * }</pre> */ public static JsonPayload of(Map<String, ?> data) { return new JsonPayload(Structs.newStruct(data)); }
/** Creates a log entry payload given its JSON data represented as a protobuf struct. */ public static JsonPayload of(Struct data) { return new JsonPayload(data); }
/** * Creates a log entry payload given its JSON data represented as a map. The provided map is * copied into a {@link Struct} object. * * <p>Notice that all numbers (int, long, float and double) are serialized as double values. * Enums are serialized as strings. * * <p>Example usage of {@code JsonPayload}: * * <pre>{@code * List<Long> listValue = Arrays.asList(1L, 2L); * Map<String, Object> innerMap = new HashMap<String, Object>(); * innerMap.put("booleanValue", true); * innerMap.put("stringValue", "stringValue"); * Map<String, Object> jsonContent = new HashMap<String, Object>(); * jsonContent.put("listValue", listValue); * jsonContent.put("integerValue", 42); * jsonContent.put("doubleValue", 42.0); * jsonContent.put("stringValue", "stringValue"); * jsonContent.put("mapValue", innerMap); * JsonPayload payload = JsonPayload.of(jsonContent); * }</pre> */ public static JsonPayload of(Map<String, ?> data) { return new JsonPayload(Structs.newStruct(data)); }
/** Creates a log entry payload given its JSON data represented as a protobuf struct. */ public static JsonPayload of(Struct data) { return new JsonPayload(data); }