Jackie-Jiang commented on code in PR #8736:
URL: https://github.com/apache/pinot/pull/8736#discussion_r878464223
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -140,11 +145,21 @@ public static <T> T stringToObject(String jsonString,
TypeReference<T> valueType
return DEFAULT_READER.forType(valueTypeRef).readValue(jsonString);
}
+ public static <T> T readValue(String jsonString, TypeReference<T>
valueTypeRef)
+ throws JsonProcessingException {
+ return DEFAULT_READER.forType(valueTypeRef).readValue(jsonString);
+ }
+
public static JsonNode stringToJsonNode(String jsonString)
throws IOException {
return DEFAULT_READER.readTree(jsonString);
}
+ public static JsonNode readTree(String jsonString)
Review Comment:
Equivalent to `stringToJsonNode(String jsonString)`?
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -229,6 +249,10 @@ public static JsonNode objectToJsonNode(Object object) {
return DEFAULT_MAPPER.valueToTree(object);
}
+ public static JsonNode valueToTree(Object object) {
Review Comment:
Equivalent to `objectToJsonNode(Object object)`?
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -81,7 +81,7 @@ private JsonUtils() {
public static final ObjectReader DEFAULT_READER = DEFAULT_MAPPER.reader();
public static final ObjectWriter DEFAULT_WRITER = DEFAULT_MAPPER.writer();
public static final ObjectWriter DEFAULT_PRETTY_WRITER =
DEFAULT_MAPPER.writerWithDefaultPrettyPrinter();
- private static final TypeReference<HashMap<String, Object>>
GENERIC_JSON_TYPE =
+ public static final TypeReference<HashMap<String, Object>> GENERIC_JSON_TYPE
=
Review Comment:
Suggest not exposing this one. We may add a helper method
`stringToMap(String jsonString)`
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -90,6 +90,11 @@ public static <T> T stringToObject(String jsonString,
Class<T> valueType)
return DEFAULT_READER.forType(valueType).readValue(jsonString);
}
+ public static <T> T readValue(String jsonString, Class<T> valueType)
Review Comment:
Is this the equivalent to `stringToObject(String jsonString, Class<T>
valueType)`? If so, let's use the existing one because keeping 2 util methods
with same functionality can be confusing
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -600,4 +625,16 @@ private static void addFieldToPinotSchema(Schema
pinotSchema, DataType dataType,
}
}
}
+
+ public static Map<String, Object> defaultConvertValue(JsonNode node) {
Review Comment:
Suggest renaming it to `jsonNodeToMap` and move it under `jsonNodeToObject()`
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -600,4 +625,16 @@ private static void addFieldToPinotSchema(Schema
pinotSchema, DataType dataType,
}
}
}
+
+ public static Map<String, Object> defaultConvertValue(JsonNode node) {
+ return DEFAULT_MAPPER.convertValue(node, GENERIC_JSON_TYPE);
+ }
+
+ public static <T> T convertValue(JsonNode node, TypeReference<T>
typeReference) {
+ return DEFAULT_MAPPER.convertValue(node, typeReference);
+ }
+
+ public static <T> T convertValue(JsonNode node, Class<T> clazz) {
Review Comment:
Equivalent to `jsonNodeToObject(JsonNode jsonNode, Class<T> valueType)`?
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -215,6 +230,11 @@ public static String objectToString(Object object)
return DEFAULT_WRITER.writeValueAsString(object);
}
+ public static Object writeValueAsString(Object object)
Review Comment:
Equivalent to `objectToString(Object object)`?
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -475,6 +499,7 @@ public static Schema getPinotSchemaFromJsonFile(File
jsonFile,
if (fieldsToUnnest == null) {
fieldsToUnnest = new ArrayList<>();
}
+ Preconditions.checkNotNull(jsonNode, "the JSON data shall be an object but
it is null");
Review Comment:
Good catch. Let's annotate the return of `fileToFirstJsonNode()` as
`Nullable`
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -140,11 +145,21 @@ public static <T> T stringToObject(String jsonString,
TypeReference<T> valueType
return DEFAULT_READER.forType(valueTypeRef).readValue(jsonString);
}
+ public static <T> T readValue(String jsonString, TypeReference<T>
valueTypeRef)
Review Comment:
Equivalent to `stringToObject(String jsonString, TypeReference<T>
valueTypeRef)`?
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/JsonUtils.java:
##########
@@ -600,4 +625,16 @@ private static void addFieldToPinotSchema(Schema
pinotSchema, DataType dataType,
}
}
}
+
+ public static Map<String, Object> defaultConvertValue(JsonNode node) {
+ return DEFAULT_MAPPER.convertValue(node, GENERIC_JSON_TYPE);
+ }
+
+ public static <T> T convertValue(JsonNode node, TypeReference<T>
typeReference) {
Review Comment:
Equivalent to `jsonNodeToObject(JsonNode jsonNode, TypeReference<T>
valueTypeRef)`?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]