FrankChen021 commented on code in PR #12468:
URL: https://github.com/apache/druid/pull/12468#discussion_r855935269
##########
core/src/main/java/org/apache/druid/java/util/common/jackson/JacksonUtils.java:
##########
@@ -51,6 +58,37 @@ public static <T> T readValue(ObjectMapper mapper, byte[]
bytes, Class<T> valueC
}
}
+ /**
+ * Returns a serializer for a particular class. If you have a {@link
SerializerProvider}, this is better than calling
+ * {@link JsonGenerator#writeObject(Object)} or {@link
ObjectMapper#writeValue(JsonGenerator, Object)}, because it
+ * avoids re-creating the {@link SerializerProvider} for each serialized
object.
+ */
+ public static JsonSerializer<Object> getSerializer(final SerializerProvider
serializerProvider, final Class<?> clazz)
+ throws JsonMappingException
+ {
+ // cache = true, property = null because this is what
DefaultSerializerProvider.serializeValue would do.
+ return serializerProvider.findTypedValueSerializer(clazz, true, null);
+ }
+
+ /**
+ * Serializes an object using a {@link JsonGenerator}. If you have a {@link
SerializerProvider}, this is better than
+ * calling {@link JsonGenerator#writeObject(Object)}, because it avoids
re-creating the {@link SerializerProvider}
+ * for each serialized object.
+ */
+ public static void writeObjectUsingSerializerProvider(
+ final JsonGenerator jsonGenerator,
Review Comment:
Since this helper API is used to replace`ObjectMapper.writeValue` and
`JsonGenerator.writeObject`, can we prohibite these two methods in the
druid-forbidden-apis.txt?
--
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]