Skip to content

Commit

Permalink
Fixed #1284
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 19, 2016
1 parent e1375b0 commit 398a5c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Project: jackson-databind
using `JsonInclude.Include.CUSTOM`
#1035: `@JsonAnySetter` assumes key of `String`, does not consider declared type.
(reported by Michael F)
#1284: Make `StdKeySerializers` use new `JsonGenerator.writeFieldId()` for `int`/`long` keys
#1320: Add `ObjectNode.put(String, BigInteger)`
(proposed by Jan L)
#1341: `DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public static JsonSerializer<Object> getStdKeySerializer(SerializationConfig con
if (rawKeyType == String.class) {
return DEFAULT_STRING_SERIALIZER;
}
if ((rawKeyType == Integer.class) || (rawKeyType == Integer.TYPE)) {
return new Default(Default.TYPE_INTEGER, rawKeyType);
}
if ((rawKeyType == Long.class) || (rawKeyType == Long.TYPE)) {
return new Default(Default.TYPE_LONG, rawKeyType);
}
if (rawKeyType.isPrimitive() || Number.class.isAssignableFrom(rawKeyType)) {
// 28-Jun-2016, tatu: Used to just return DEFAULT_KEY_SERIALIZER, but makes
// more sense to use simpler one directly
Expand Down Expand Up @@ -121,7 +127,9 @@ public static class Default extends StdSerializer<Object> {
final static int TYPE_CALENDAR = 2;
final static int TYPE_CLASS = 3;
final static int TYPE_ENUM = 4;
final static int TYPE_TO_STRING = 5;
final static int TYPE_INTEGER = 5; // since 2.9
final static int TYPE_LONG = 6; // since 2.9
final static int TYPE_TO_STRING = 7;

protected final int _typeId;

Expand Down Expand Up @@ -149,6 +157,10 @@ public void serialize(Object value, JsonGenerator g, SerializerProvider provider
g.writeFieldName(str);
}
break;
case TYPE_INTEGER:
case TYPE_LONG:
g.writeFieldId(((Number) value).longValue());
break;
case TYPE_TO_STRING:
default:
g.writeFieldName(value.toString());
Expand Down

0 comments on commit 398a5c5

Please sign in to comment.