viktorsomogyi commented on a change in pull request #4090: URL: https://github.com/apache/kafka/pull/4090#discussion_r430997918
########## File path: core/src/main/scala/kafka/utils/Json.scala ########## @@ -65,6 +63,16 @@ object Json { catch { case e: JsonProcessingException => Left(e) } } + /** + * Parse a JSON string into a JsonValue if possible. It returns an `Either` where `Left` will be an exception and + * `Right` is the `JsonValue`. + * @param input a JSON string to parse + * @return An `Either` which in case of `Left` means an exception and `Right` is the actual return value. + */ + def tryParseFull(input: String): Either[JsonProcessingException, JsonValue] = + try Right(mapper.readTree(input)).map(JsonValue(_)) Review comment: I don't think that's possible in this case as with the String parameter you pass in the Json string itself which can either be `null` in which case an `IllegalArgumentException` will be thrown or some kind of value which can or can't be parsed and then the method returns with `Either`. In the cases where you read the Json in from an InputStream or a Reader it is possible to return `null` as you can terminate the stream without providing any actual content (but in the String you provide the content itself). If you want, I can handle the possible `null` but I don't think it's possible with `readTree(String)`. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org