Skip to content

Commit

Permalink
Fix #965
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 10, 2015
1 parent 16aa305 commit ca6c3fc
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 76 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Project: jackson-databind
(contributed by Benson M)
#949: Report the offending substring when number parsing fails
(contributed by Jesse W)
#965: BigDecimal values via @JsonTypeInfo/@JsonSubTypes get rounded
(reported by gmjabs@github)

2.6.2 (14-Sep-2015)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2507,6 +2507,9 @@ public <T extends JsonNode> T valueToTree(Object fromValue)
{
if (fromValue == null) return null;
TokenBuffer buf = new TokenBuffer(this, false);
if (isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
buf = buf.forceUseOfBigDecimal(true);
}
JsonNode result;
try {
writeValue(buf, fromValue);
Expand Down Expand Up @@ -3423,6 +3426,9 @@ protected Object _convert(Object fromValue, JavaType toValueType)

// Then use TokenBuffer, which is a JsonGenerator:
TokenBuffer buf = new TokenBuffer(this, false);
if (isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
buf = buf.forceUseOfBigDecimal(true);
}
try {
// inlined 'writeValue' with minor changes:
// first: disable wrapping when writing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
}
// Ok then, let's collect the whole field; name and value
if (unknown == null) {
unknown = new TokenBuffer(p);
unknown = new TokenBuffer(p, ctxt);
}
unknown.writeFieldName(propName);
unknown.copyCurrentStructure(p);
Expand Down Expand Up @@ -522,7 +522,7 @@ protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext c
if (_propertyBasedCreator != null) {
return deserializeUsingPropertyBasedWithUnwrapped(p, ctxt);
}
TokenBuffer tokens = new TokenBuffer(p);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
final Object bean = _valueInstantiator.createUsingDefault(ctxt);

Expand Down Expand Up @@ -581,7 +581,7 @@ protected Object deserializeWithUnwrapped(JsonParser p, DeserializationContext c
if (t == JsonToken.START_OBJECT) {
t = p.nextToken();
}
TokenBuffer tokens = new TokenBuffer(p);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
Expand Down Expand Up @@ -624,7 +624,7 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p, Deseri
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);

TokenBuffer tokens = new TokenBuffer(p);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();

JsonToken t = p.getCurrentToken();
Expand Down Expand Up @@ -780,7 +780,7 @@ protected Object deserializeUsingPropertyBasedWithExternalTypeId(JsonParser p, D
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);

TokenBuffer tokens = new TokenBuffer(p);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();

JsonToken t = p.getCurrentToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,10 +1037,10 @@ protected Object _handleTypedObjectId(JsonParser jp, DeserializationContext ctxt
* @since 2.3
*/
@SuppressWarnings("resource") // TokenBuffers don't need close, nor parser thereof
protected Object _convertObjectId(JsonParser jp, DeserializationContext ctxt,
protected Object _convertObjectId(JsonParser p, DeserializationContext ctxt,
Object rawId, JsonDeserializer<Object> idDeser) throws IOException
{
TokenBuffer buf = new TokenBuffer(jp);
TokenBuffer buf = new TokenBuffer(p, ctxt);
if (rawId instanceof String) {
buf.writeString((String) rawId);
} else if (rawId instanceof Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ protected final Object _deserializeUsingPropertyBased(final JsonParser jp,
}
// Ok then, let's collect the whole field; name and value
if (unknown == null) {
unknown = new TokenBuffer(jp);
unknown = new TokenBuffer(jp, ctxt);
}
unknown.writeFieldName(propName);
unknown.copyCurrentStructure(jp);
Expand Down Expand Up @@ -458,7 +458,7 @@ protected Object deserializeWithUnwrapped(JsonParser jp, DeserializationContext
if (_propertyBasedCreator != null) {
return deserializeUsingPropertyBasedWithUnwrapped(jp, ctxt);
}
TokenBuffer tokens = new TokenBuffer(jp);
TokenBuffer tokens = new TokenBuffer(jp, ctxt);
tokens.writeStartObject();
Object bean = _valueInstantiator.createUsingDefault(ctxt);

Expand Down Expand Up @@ -516,7 +516,7 @@ protected Object deserializeWithUnwrapped(JsonParser jp,
if (t == JsonToken.START_OBJECT) {
t = jp.nextToken();
}
TokenBuffer tokens = new TokenBuffer(jp);
TokenBuffer tokens = new TokenBuffer(jp, ctxt);
tokens.writeStartObject();
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
Expand Down Expand Up @@ -560,7 +560,7 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p,
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);

TokenBuffer tokens = new TokenBuffer(p);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.writeStartObject();

JsonToken t = p.getCurrentToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public boolean handleTypePropertyValue(JsonParser jp, DeserializationContext ctx
*
* @return True, if the given property was properly handled
*/
public boolean handlePropertyValue(JsonParser jp, DeserializationContext ctxt,
public boolean handlePropertyValue(JsonParser p, DeserializationContext ctxt,
String propName, Object bean) throws IOException
{
Integer I = _nameToPropertyIndex.get(propName);
Expand All @@ -99,13 +99,13 @@ public boolean handlePropertyValue(JsonParser jp, DeserializationContext ctxt,
ExtTypedProperty prop = _properties[index];
boolean canDeserialize;
if (prop.hasTypePropertyName(propName)) {
_typeIds[index] = jp.getText();
jp.skipChildren();
_typeIds[index] = p.getText();
p.skipChildren();
canDeserialize = (bean != null) && (_tokens[index] != null);
} else {
@SuppressWarnings("resource")
TokenBuffer tokens = new TokenBuffer(jp);
tokens.copyCurrentStructure(jp);
TokenBuffer tokens = new TokenBuffer(p, ctxt);
tokens.copyCurrentStructure(p);
_tokens[index] = tokens;
canDeserialize = (bean != null) && (_typeIds[index] != null);
}
Expand All @@ -116,7 +116,7 @@ public boolean handlePropertyValue(JsonParser jp, DeserializationContext ctxt,
String typeId = _typeIds[index];
// clear stored data, to avoid deserializing+setting twice:
_typeIds[index] = null;
_deserializeAndSet(jp, ctxt, bean, index, typeId);
_deserializeAndSet(p, ctxt, bean, index, typeId);
_tokens[index] = null;
}
return true;
Expand Down Expand Up @@ -228,8 +228,7 @@ protected final Object _deserialize(JsonParser p, DeserializationContext ctxt,
if (t == JsonToken.VALUE_NULL) {
return null;
}

TokenBuffer merged = new TokenBuffer(p);
TokenBuffer merged = new TokenBuffer(p, ctxt);
merged.writeStartArray();
merged.writeString(typeId);
merged.copyCurrentStructure(p2);
Expand All @@ -255,7 +254,7 @@ protected final void _deserializeAndSet(JsonParser p, DeserializationContext ctx
_properties[index].getProperty().set(bean, null);
return;
}
TokenBuffer merged = new TokenBuffer(p);
TokenBuffer merged = new TokenBuffer(p, ctxt);
merged.writeStartArray();
merged.writeString(typeId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class TokenBufferDeserializer extends StdScalarDeserializer<TokenBuffer>
public TokenBufferDeserializer() { super(TokenBuffer.class); }

@Override
public TokenBuffer deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return createBufferInstance(jp).deserialize(jp, ctxt);
public TokenBuffer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return createBufferInstance(p).deserialize(p, ctxt);
}

protected TokenBuffer createBufferInstance(JsonParser jp) {
return new TokenBuffer(jp);
protected TokenBuffer createBufferInstance(JsonParser p) {
return new TokenBuffer(p);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,37 +80,37 @@ public Object deserializeTypedFromAny(JsonParser jp, DeserializationContext ctxt
* deserialization.
*/
@SuppressWarnings("resource")
protected Object _deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
protected Object _deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// 02-Aug-2013, tatu: May need to use native type ids
if (jp.canReadTypeId()) {
Object typeId = jp.getTypeId();
if (p.canReadTypeId()) {
Object typeId = p.getTypeId();
if (typeId != null) {
return _deserializeWithNativeTypeId(jp, ctxt, typeId);
return _deserializeWithNativeTypeId(p, ctxt, typeId);
}
}
boolean hadStartArray = jp.isExpectedStartArrayToken();
String typeId = _locateTypeId(jp, ctxt);
boolean hadStartArray = p.isExpectedStartArrayToken();
String typeId = _locateTypeId(p, ctxt);
JsonDeserializer<Object> deser = _findDeserializer(ctxt, typeId);
// Minor complication: we may need to merge type id in?
if (_typeIdVisible
// 06-Oct-2014, tatu: To fix [databind#408], must distinguish between
// internal and external properties
// TODO: but does it need to be injected in external case? Why not?
&& !_usesExternalId()
&& jp.getCurrentToken() == JsonToken.START_OBJECT) {
&& p.getCurrentToken() == JsonToken.START_OBJECT) {
// but what if there's nowhere to add it in? Error? Or skip? For now, skip.
TokenBuffer tb = new TokenBuffer(null, false);
tb.writeStartObject(); // recreate START_OBJECT
tb.writeFieldName(_typePropertyName);
tb.writeString(typeId);
jp = JsonParserSequence.createFlattened(tb.asParser(jp), jp);
jp.nextToken();
p = JsonParserSequence.createFlattened(tb.asParser(p), p);
p.nextToken();
}
Object value = deser.deserialize(jp, ctxt);
Object value = deser.deserialize(p, ctxt);
// And then need the closing END_ARRAY
if (hadStartArray && jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
if (hadStartArray && p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"expected closing END_ARRAY after type information and deserialized value");
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Object deserializeTypedFromObject(JsonParser jp, DeserializationContext c
return _deserializeTypedForId(jp, ctxt, tb);
}
if (tb == null) {
tb = new TokenBuffer(null, false);
tb = new TokenBuffer(jp, ctxt);
}
tb.writeFieldName(name);
tb.copyCurrentStructure(jp);
Expand All @@ -108,7 +108,7 @@ protected Object _deserializeTypedForId(JsonParser jp, DeserializationContext ct
JsonDeserializer<Object> deser = _findDeserializer(ctxt, typeId);
if (_typeIdVisible) { // need to merge id back in JSON input?
if (tb == null) {
tb = new TokenBuffer(null, false);
tb = new TokenBuffer(jp, ctxt);
}
tb.writeFieldName(jp.getCurrentName());
tb.writeString(typeId);
Expand Down
Loading

0 comments on commit ca6c3fc

Please sign in to comment.