|
15 | 15 | package com.fasterxml.jackson.dataformat.ion;
|
16 | 16 |
|
17 | 17 | import com.fasterxml.jackson.core.JsonParser;
|
| 18 | +import com.fasterxml.jackson.core.JsonParseException; |
18 | 19 | import com.fasterxml.jackson.core.JsonToken;
|
19 | 20 | import com.fasterxml.jackson.core.StreamReadCapability;
|
20 | 21 |
|
@@ -125,4 +126,54 @@ public void testParserCapabilities() throws Exception {
|
125 | 126 | }
|
126 | 127 | }
|
127 | 128 |
|
| 129 | + |
| 130 | + @Test(expected = JsonParseException.class) |
| 131 | + public void testIonExceptionIsWrapped() throws IOException { |
| 132 | + IonFactory f = new IonFactory(); |
| 133 | + try (IonParser parser = (IonParser) f.createParser("[ 12, true ) ]")) { |
| 134 | + Assert.assertEquals(JsonToken.START_ARRAY, parser.nextToken()); |
| 135 | + Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextValue()); |
| 136 | + Assert.assertEquals(12, parser.getIntValue()); |
| 137 | + Assert.assertEquals(JsonToken.VALUE_TRUE, parser.nextValue()); |
| 138 | + parser.nextValue(); |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + @Test(expected = JsonParseException.class) |
| 143 | + public void testUnknownSymbolExceptionForValueIsWrapped() throws IOException { |
| 144 | + IonFactory f = new IonFactory(); |
| 145 | + try (IonParser parser = (IonParser) f.createParser("[ 12, $99 ]")) { |
| 146 | + Assert.assertEquals(JsonToken.START_ARRAY, parser.nextToken()); |
| 147 | + Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextValue()); |
| 148 | + Assert.assertEquals(12, parser.getIntValue()); |
| 149 | + Assert.assertEquals(JsonToken.VALUE_STRING, parser.nextValue()); |
| 150 | + parser.getValueAsString(); // Should encounter unknown symbol and fail |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + @Test(expected = JsonParseException.class) |
| 155 | + public void testUnknownSymbolExceptionForFieldNameIsWrapped() throws IOException { |
| 156 | + IonFactory f = new IonFactory(); |
| 157 | + try (IonParser parser = (IonParser) f.createParser("{ a: 1, $99: 2 }")) { |
| 158 | + Assert.assertEquals(JsonToken.START_OBJECT, parser.nextToken()); |
| 159 | + Assert.assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); |
| 160 | + Assert.assertEquals("a", parser.getCurrentName()); |
| 161 | + Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextValue()); |
| 162 | + Assert.assertEquals(1, parser.getIntValue()); |
| 163 | + parser.nextValue(); // Should encounter unknown symbol and fail |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + @Test(expected = JsonParseException.class) |
| 168 | + public void testUnknownSymbolExceptionForAnnotationIsWrapped() throws IOException { |
| 169 | + IonFactory f = new IonFactory(); |
| 170 | + try (IonParser parser = (IonParser) f.createParser("{ a: $99::1 }")) { |
| 171 | + Assert.assertEquals(JsonToken.START_OBJECT, parser.nextToken()); |
| 172 | + Assert.assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); |
| 173 | + Assert.assertEquals("a", parser.getCurrentName()); |
| 174 | + Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextValue()); |
| 175 | + Assert.assertEquals(1, parser.getIntValue()); |
| 176 | + parser.getTypeAnnotations(); // Should encounter unknown symbol and fail |
| 177 | + } |
| 178 | + } |
128 | 179 | }
|
0 commit comments