Skip to content

Commit

Permalink
Fix #2657
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 26, 2020
1 parent 8af03c1 commit 2270e10
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Project: jackson-databind
#2643: Change default textual serialization of `java.util.Date`/`Calendar`
to include colon in timezone offset
#2647: Add `ObjectMapper.createParser()` and `createGenerator()` methods
#2657: Allow serialization of `Properties` with non-String values
#2663: Add new factory method for creating custom `EnumValues` to pass to `EnumDeserializer
(requested by Rafal K)
- Add `SerializerProvider.findContentValueSerializer()` methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,18 @@ public static MapSerializer construct(Set<String> ignoredEntries, JavaType mapTy
Object filterId)
{
JavaType keyType, valueType;

if (mapType == null) {
keyType = valueType = UNSPECIFIED_TYPE;
} else {
keyType = mapType.getKeyType();
valueType = mapType.getContentType();
if (mapType.hasRawClass(java.util.Properties.class)) {
// 25-Mar-2020, tatu: [databind#2657] Since non-standard Properties may actually
// contain non-Strings, demote value type to raw `Object`
valueType = TypeFactory.unknownType();
} else {
valueType = mapType.getContentType();
}
}
// If value type is final, it's same as forcing static value typing:
if (!staticValueType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,15 @@ public void testVoidSerialization() throws Exception
assertEquals(aposToQuotes("{'value':null}"),
MAPPER.writeValueAsString(new VoidBean()));
}

// [databind#2657]
public void testNonStandardProperties() throws Exception
{
Properties properties = new Properties();
// Bad usage: Properties should NOT contain non-Strings. But
// some do that regardless and compiler won't stop it so.
properties.put("key", 1);
String json = MAPPER.writeValueAsString(properties);
assertEquals("{\"key\":1}", json);
}
}

0 comments on commit 2270e10

Please sign in to comment.