Skip to content

Commit 329cef3

Browse files
committed
Convert Smile backend
1 parent 182869c commit 329cef3

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

smile/src/main/java/tools/jackson/dataformat/smile/SmileParser.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,21 @@ protected void _parseNumericValue() throws JacksonException
22642264
throw _constructReadException("Current token (%s) not numeric, cannot use numeric value accessors", _currToken);
22652265
}
22662266

2267+
@Override
2268+
protected boolean _parseNumericValueIfNumber() throws JacksonException
2269+
{
2270+
if (_tokenIncomplete) {
2271+
_tokenIncomplete = false;
2272+
int tb = _typeAsInt;
2273+
// ensure we got a numeric type with value that is lazily parsed
2274+
if ((tb >> 5) == 1) {
2275+
_finishNumberToken(tb);
2276+
return true;
2277+
}
2278+
}
2279+
return false;
2280+
}
2281+
22672282
/*
22682283
@Override // since 2.6
22692284
protected int _parseIntValue() throws JacksonException

smile/src/main/java/tools/jackson/dataformat/smile/SmileParserBase.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,22 @@ public final boolean mayContainRawBinary() {
253253
@Override
254254
protected abstract void _closeInput() throws JacksonException;
255255

256+
/**
257+
* Method called to complete parsing of a numeric value: will throw
258+
* {@link StreamReadException} if current token is not numeric.
259+
*
260+
* @throws StreamReadException if current token is not numeric
261+
*/
256262
protected abstract void _parseNumericValue() throws JacksonException;
257263

264+
/**
265+
* Similar to {@link #_parseNumericValue()}, but will not throw exception
266+
* if the current token is not a numeric value.
267+
*
268+
* @return {@code true} if current token is numeric; {@code false} otherwise
269+
*/
270+
protected abstract boolean _parseNumericValueIfNumber() throws JacksonException;
271+
258272
// public abstract int releaseBuffered(OutputStream out) throws JacksonException;
259273
// public abstract Object getInputSource();
260274

@@ -391,7 +405,9 @@ public final Number getNumberValueExact() throws JacksonException {
391405
public final NumberType getNumberType() throws JacksonException
392406
{
393407
if (_numTypesValid == NR_UNKNOWN) {
394-
_parseNumericValue(); // will also check event type
408+
if (!_parseNumericValueIfNumber()) {
409+
return null;
410+
}
395411
}
396412
return _numberType;
397413
}

smile/src/main/java/tools/jackson/dataformat/smile/async/NonBlockingParserBase.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,16 @@ protected void _closeInput() {
210210
// in future
211211
@Override
212212
protected void _parseNumericValue() throws JacksonException {
213-
if (_currToken == JsonToken.VALUE_NUMBER_INT || _currToken == JsonToken.VALUE_NUMBER_FLOAT) {
214-
return;
213+
if (_currToken != JsonToken.VALUE_NUMBER_INT && _currToken != JsonToken.VALUE_NUMBER_FLOAT) {
214+
_reportError("Current token (%s) not numeric, can not use numeric value accessors", _currToken);
215215
}
216-
_reportError("Current token (%s) not numeric, can not use numeric value accessors", _currToken);
216+
}
217+
218+
@Override
219+
protected boolean _parseNumericValueIfNumber() throws JacksonException
220+
{
221+
// No incomplete values so just return
222+
return false;
217223
}
218224

219225
/*

smile/src/test/java/tools/jackson/dataformat/smile/parse/SmileNumberParsingGetType1433Test.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import org.junit.jupiter.api.Test;
44

55
import tools.jackson.core.*;
6-
import tools.jackson.core.exc.StreamReadException;
76
import tools.jackson.dataformat.smile.SmileFactory;
87
import tools.jackson.dataformat.smile.BaseTestForSmile;
98

109
import static org.junit.jupiter.api.Assertions.assertEquals;
1110
import static org.junit.jupiter.api.Assertions.assertNull;
12-
import static org.junit.jupiter.api.Assertions.fail;
1311

1412
public class SmileNumberParsingGetType1433Test
1513
extends BaseTestForSmile
@@ -59,12 +57,8 @@ void getNumberType() throws Exception
5957

6058
private void _verifyGetNumberTypeFail(JsonParser p, String token) throws Exception
6159
{
62-
try {
63-
p.getNumberType();
64-
fail("Should not pass");
65-
} catch (StreamReadException e) {
66-
verifyException(e, "Current token ("+token+") not numeric, cannot use numeric");
67-
}
60+
// In 2.x got exception; in 3.x null
61+
assertNull(p.getNumberType());
6862
}
6963

7064
private SmileFactory jsonFactory() {

0 commit comments

Comments
 (0)