|
6 | 6 | package io.jooby.internal.jackson3; |
7 | 7 |
|
8 | 8 | import io.jooby.exception.MissingValueException; |
| 9 | +import io.jooby.exception.TypeMismatchException; |
9 | 10 | import io.jooby.jsonrpc.JsonRpcDecoder; |
10 | 11 | import io.jooby.jsonrpc.JsonRpcReader; |
11 | 12 | import tools.jackson.databind.JsonNode; |
@@ -61,27 +62,47 @@ public boolean nextIsNull(String name) { |
61 | 62 |
|
62 | 63 | @Override |
63 | 64 | public int nextInt(String name) { |
64 | | - return requireNode(name).asInt(); |
| 65 | + var node = requireNode(name); |
| 66 | + if (node.isInt()) { |
| 67 | + return node.asInt(); |
| 68 | + } |
| 69 | + throw new TypeMismatchException(name, int.class); |
65 | 70 | } |
66 | 71 |
|
67 | 72 | @Override |
68 | 73 | public long nextLong(String name) { |
69 | | - return requireNode(name).asLong(); |
| 74 | + var node = requireNode(name); |
| 75 | + if (node.isLong()) { |
| 76 | + return node.longValue(); |
| 77 | + } |
| 78 | + throw new TypeMismatchException(name, long.class); |
70 | 79 | } |
71 | 80 |
|
72 | 81 | @Override |
73 | 82 | public boolean nextBoolean(String name) { |
74 | | - return requireNode(name).asBoolean(); |
| 83 | + var node = requireNode(name); |
| 84 | + if (node.isBoolean()) { |
| 85 | + return node.booleanValue(); |
| 86 | + } |
| 87 | + throw new TypeMismatchException(name, boolean.class); |
75 | 88 | } |
76 | 89 |
|
77 | 90 | @Override |
78 | 91 | public double nextDouble(String name) { |
79 | | - return requireNode(name).asDouble(); |
| 92 | + var node = requireNode(name); |
| 93 | + if (node.isDouble()) { |
| 94 | + return node.asDouble(); |
| 95 | + } |
| 96 | + throw new TypeMismatchException(name, double.class); |
80 | 97 | } |
81 | 98 |
|
82 | 99 | @Override |
83 | 100 | public String nextString(String name) { |
84 | | - return requireNode(name).asText(); |
| 101 | + var node = requireNode(name); |
| 102 | + if (node.isString()) { |
| 103 | + return node.asString(); |
| 104 | + } |
| 105 | + throw new TypeMismatchException(name, String.class); |
85 | 106 | } |
86 | 107 |
|
87 | 108 | @Override |
|
0 commit comments