Skip to content

Commit 398a5c5

Browse files
committed
Fixed #1284
1 parent e1375b0 commit 398a5c5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Project: jackson-databind
1616
using `JsonInclude.Include.CUSTOM`
1717
#1035: `@JsonAnySetter` assumes key of `String`, does not consider declared type.
1818
(reported by Michael F)
19+
#1284: Make `StdKeySerializers` use new `JsonGenerator.writeFieldId()` for `int`/`long` keys
1920
#1320: Add `ObjectNode.put(String, BigInteger)`
2021
(proposed by Jan L)
2122
#1341: `DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY`

src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializers.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public static JsonSerializer<Object> getStdKeySerializer(SerializationConfig con
4040
if (rawKeyType == String.class) {
4141
return DEFAULT_STRING_SERIALIZER;
4242
}
43+
if ((rawKeyType == Integer.class) || (rawKeyType == Integer.TYPE)) {
44+
return new Default(Default.TYPE_INTEGER, rawKeyType);
45+
}
46+
if ((rawKeyType == Long.class) || (rawKeyType == Long.TYPE)) {
47+
return new Default(Default.TYPE_LONG, rawKeyType);
48+
}
4349
if (rawKeyType.isPrimitive() || Number.class.isAssignableFrom(rawKeyType)) {
4450
// 28-Jun-2016, tatu: Used to just return DEFAULT_KEY_SERIALIZER, but makes
4551
// more sense to use simpler one directly
@@ -121,7 +127,9 @@ public static class Default extends StdSerializer<Object> {
121127
final static int TYPE_CALENDAR = 2;
122128
final static int TYPE_CLASS = 3;
123129
final static int TYPE_ENUM = 4;
124-
final static int TYPE_TO_STRING = 5;
130+
final static int TYPE_INTEGER = 5; // since 2.9
131+
final static int TYPE_LONG = 6; // since 2.9
132+
final static int TYPE_TO_STRING = 7;
125133

126134
protected final int _typeId;
127135

@@ -149,6 +157,10 @@ public void serialize(Object value, JsonGenerator g, SerializerProvider provider
149157
g.writeFieldName(str);
150158
}
151159
break;
160+
case TYPE_INTEGER:
161+
case TYPE_LONG:
162+
g.writeFieldId(((Number) value).longValue());
163+
break;
152164
case TYPE_TO_STRING:
153165
default:
154166
g.writeFieldName(value.toString());

0 commit comments

Comments
 (0)