abhishekagarwal87 commented on code in PR #12612:
URL: https://github.com/apache/druid/pull/12612#discussion_r890870509


##########
processing/src/main/java/org/apache/druid/jackson/DefaultObjectMapper.java:
##########
@@ -61,11 +77,54 @@ public DefaultObjectMapper(JsonFactory factory)
     configure(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS, false);
     configure(SerializationFeature.INDENT_OUTPUT, false);
     configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, false);
+
+    addHandler(new DefaultDeserializationProblemHandler(serviceName));
   }
 
   @Override
   public ObjectMapper copy()
   {
     return new DefaultObjectMapper(this);
   }
+
+  /**
+   * A custom implementation of {@link #DeserializationProblemHandler} to add 
custom error message so
+   * that users know how to troubleshoot unknown type ids.
+   */
+  static class DefaultDeserializationProblemHandler extends 
DeserializationProblemHandler
+  {
+    private final String serviceName;
+
+    public DefaultDeserializationProblemHandler(@Nullable String serviceName)
+    {
+      this.serviceName = serviceName == null ? "unknown" : serviceName;
+    }
+
+    @VisibleForTesting
+    String getServiceName()
+    {
+      return serviceName;
+    }
+
+    @Override
+    public JavaType handleUnknownTypeId(DeserializationContext ctxt,
+                                        JavaType baseType, String subTypeId, 
TypeIdResolver idResolver,
+                                        String failureMsg)
+        throws IOException
+    {
+      String msg = String.format("Please make sure to load all the necessary 
extensions and jars " +
+              "with type '%s' on '%s' service. " +
+              "Could not resolve type id '%s' as a subtype of %s",
+          subTypeId, serviceName, subTypeId, 
ClassUtil.getTypeDescription(baseType));
+      throw InvalidTypeIdException.from(ctxt.getParser(), 
extraFailureMessage(msg, failureMsg), baseType, subTypeId);
+    }
+
+    private String extraFailureMessage(String msgBase, @Nullable String extra)
+    {
+      if (extra == null) {
+        return msgBase;
+      }
+      return msgBase + " " + extra;

Review Comment:
   Now, you put it that way, I am going to remove this `extra` method itself 😄 



-- 
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]

Reply via email to