[
https://issues.apache.org/jira/browse/KAFKA-21058?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jheng-Sing Chen reassigned KAFKA-21058:
---------------------------------------
Assignee: Jheng-Sing Chen (was: Chia-Ping Tsai)
> Remove the dead code from jsonNodeToInt and jsonNodeToLong
> ----------------------------------------------------------
>
> Key: KAFKA-21058
> URL: https://issues.apache.org/jira/browse/KAFKA-21058
> Project: Kafka
> Issue Type: Improvement
> Reporter: Chia-Ping Tsai
> Assignee: Jheng-Sing Chen
> Priority: Minor
>
> {{JsonConverterGenerator}} already picks {{jsonNodeToInt}} or
> {{jsonNodeToLong}} by field type, and both methods have a guard against
> string type. Hence, the string-to-number logic is gratuitous.
> {code:java}
> public static int jsonNodeToInt(JsonNode node, String about) {
> if (node.isInt()) {
> return node.asInt();
> }
> if (node.isTextual()) {
> throw new NumberFormatException(about + ": expected an integer or
> " +
> "string type, but got " + node.getNodeType());
> }
> String text = node.asText();
> if (text.startsWith("0x")) {
> try {
> return Integer.parseInt(text.substring(2), 16);
> } catch (NumberFormatException e) {
> throw new NumberFormatException(about + ": failed to " +
> "parse hexadecimal number: " + e.getMessage());
> }
> } else {
> try {
> return Integer.parseInt(text);
> } catch (NumberFormatException e) {
> throw new NumberFormatException(about + ": failed to " +
> "parse number: " + e.getMessage());
> }
> }
> } public static long jsonNodeToLong(JsonNode node, String about) {
> if (node.isLong()) {
> return node.asLong();
> }
> if (node.isTextual()) {
> throw new NumberFormatException(about + ": expected an integer or
> " +
> "string type, but got " + node.getNodeType());
> }
> String text = node.asText();
> if (text.startsWith("0x")) {
> try {
> return Long.parseLong(text.substring(2), 16);
> } catch (NumberFormatException e) {
> throw new NumberFormatException(about + ": failed to " +
> "parse hexadecimal number: " + e.getMessage());
> }
> } else {
> try {
> return Long.parseLong(text);
> } catch (NumberFormatException e) {
> throw new NumberFormatException(about + ": failed to " +
> "parse number: " + e.getMessage());
> }
> }
> }
> {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)