Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create UnknownPropertiesTest.java #3727

Closed
wants to merge 15 commits into from
Prev Previous commit
Next Next commit
wip
  • Loading branch information
pjfanning committed Jan 27, 2023
commit b8f089495f91e6017e9de37b1f2333bed79d1c8a
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.base.ParserMinimalBase;
import com.fasterxml.jackson.core.io.LazyBigDecimal;
import com.fasterxml.jackson.core.io.LazyBigInteger;
import com.fasterxml.jackson.core.io.LazyNumber;
import com.fasterxml.jackson.core.util.JacksonFeatureSet;
import com.fasterxml.jackson.databind.JsonNode;

Expand Down Expand Up @@ -263,6 +266,21 @@ public BigDecimal getDecimalValue() throws IOException {
return currentNumericNode().decimalValue();
}

@Override
public LazyNumber getLazyNumber() throws IOException {
switch (getNumberType()) {
case BIG_INTEGER:
case INT:
case LONG:
return new LazyBigInteger(getBigIntegerValue());
case BIG_DECIMAL:
case FLOAT:
case DOUBLE:
return new LazyBigDecimal(getDecimalValue());
}
throw new JsonParseException(this, "Unable to create LazyNumber from " + getText());
}

@Override
public double getDoubleValue() throws IOException {
return currentNumericNode().doubleValue();
Expand Down
51 changes: 37 additions & 14 deletions src/main/java/com/fasterxml/jackson/databind/util/TokenBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.base.ParserMinimalBase;
import com.fasterxml.jackson.core.io.LazyBigDecimal;
import com.fasterxml.jackson.core.io.LazyBigInteger;
import com.fasterxml.jackson.core.io.LazyNumber;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.json.JsonWriteContext;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.fasterxml.jackson.core.util.JacksonFeatureSet;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.util.internal.LazyBigDecimal;
import com.fasterxml.jackson.databind.util.internal.LazyBigInteger;
import com.fasterxml.jackson.databind.util.internal.LazyNumber;

/**
* Utility class used for efficient storage of {@link JsonToken}
Expand Down Expand Up @@ -1089,7 +1089,7 @@ public void copyCurrentEvent(JsonParser p) throws IOException
writeNumber(p.getIntValue());
break;
case BIG_INTEGER:
writeLazyBigInteger(p.getText(), p.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
writeLazyBigInteger(p.getLazyNumber());
break;
default:
writeNumber(p.getLongValue());
Expand All @@ -1101,11 +1101,11 @@ public void copyCurrentEvent(JsonParser p) throws IOException
// number is already decoded into a number (in which case might as well
// access as number); or is still retained as text (in which case we
// should further defer decoding that may not need BigDecimal):
writeLazyBigDecimal(p.getText(), p.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
writeLazyBigDecimal(p.getLazyNumber());
} else {
switch (p.getNumberType()) {
case BIG_DECIMAL:
writeLazyBigDecimal(p.getText(), p.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
writeLazyBigDecimal(p.getLazyNumber());
break;
case FLOAT:
writeNumber(p.getFloatValue());
Expand Down Expand Up @@ -1247,15 +1247,15 @@ private void _copyBufferValue(JsonParser p, JsonToken t) throws IOException
writeNumber(p.getIntValue());
break;
case BIG_INTEGER:
writeLazyBigInteger(p.getText(), p.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
writeLazyBigInteger(p.getLazyNumber());
break;
default:
writeNumber(p.getLongValue());
}
break;
case VALUE_NUMBER_FLOAT:
if (_forceBigDecimal) {
writeLazyBigDecimal(p.getText(), p.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
writeLazyBigDecimal(p.getLazyNumber());
} else {
// 09-Jul-2020, tatu: Used to just copy using most optimal method, but
// issues like [databind#2644] force to use exact, not optimal type
Expand Down Expand Up @@ -1331,19 +1331,19 @@ protected final void _append(JsonToken type, Object value)
}
*/

private void writeLazyBigInteger(final String v, final boolean useFastParser) throws IOException {
if (v == null) {
private void writeLazyBigInteger(final LazyNumber lazyNumber) throws IOException {
if (lazyNumber == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_NUMBER_INT, new LazyBigInteger(v, useFastParser));
_appendValue(JsonToken.VALUE_NUMBER_INT, lazyNumber);
}
}

private void writeLazyBigDecimal(final String v, final boolean useFastParser) throws IOException {
if (v == null) {
private void writeLazyBigDecimal(final LazyNumber lazyNumber) throws IOException {
if (lazyNumber == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_NUMBER_FLOAT, new LazyBigDecimal(v, useFastParser));
_appendValue(JsonToken.VALUE_NUMBER_FLOAT, lazyNumber);
}
}

Expand Down Expand Up @@ -1845,6 +1845,29 @@ public BigDecimal getDecimalValue() throws IOException
return BigDecimal.valueOf(n.doubleValue());
}

@Override
public LazyNumber getLazyNumber() throws IOException {
Object value = _currentObject();
if (value instanceof LazyNumber) {
return (LazyNumber) value;
} else if (value instanceof String) {
return new LazyBigDecimal((String) value, isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
} else if (value instanceof BigDecimal) {
return new LazyBigDecimal((BigDecimal) value);
} else if (value instanceof BigInteger) {
return new LazyBigInteger((BigInteger) value);
} else if (value instanceof Integer) {
return new LazyBigInteger(getBigIntegerValue());
} else if (value instanceof Long) {
return new LazyBigInteger(getBigIntegerValue());
} else if (value instanceof Double) {
return new LazyBigDecimal(getDecimalValue());
} else if (value instanceof Float) {
return new LazyBigDecimal(getDecimalValue());
}
throw new JsonParseException(this, "unable to get LazyNumber from " + getText());
}

@Override
public double getDoubleValue() throws IOException {
return getNumberValue().doubleValue();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.