Skip to content

Commit

Permalink
Fix #1231
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 19, 2016
1 parent 9d3de8c commit ebadfd2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ Yoann Rodière (fenrhil@github)
Mark Woon (markwoon@github)
* Reported #1178: `@JsonSerialize(contentAs=superType)` behavior disallowed in 2.7
(2.7.4)
* Reported #1231: `@JsonSerialize(as=superType)` behavior disallowed in 2.7.4
(2.7.5)

Tom Mack (tommack@github)
* Reported #1208: treeToValue doesn't handle POJONodes that contain exactly
Expand Down
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Project: jackson-databind
(reported by Nick B)
#1228: @JsonAnySetter does not deserialize null to Deserializer's NullValue
(contributed by Eric S)
#1231: `@JsonSerialize(as=superType)` behavior disallowed in 2.7.4
(reported by Mark W)

2.7.4 (29-Apr-2016)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,19 @@ public JavaType refineSerializationType(final MapperConfig<?> config,
// static typing this way
type = type.withStaticTyping();
} else {
Class<?> currRaw = type.getRawClass();
try {
// 11-Oct-2015, tatu: For deser, we call `TypeFactory.constructSpecializedType()`,
// may be needed here too in future?
type = tf.constructGeneralizedType(type, serClass);
if (serClass.isAssignableFrom(currRaw)) { // common case
type = tf.constructGeneralizedType(type, serClass);
} else if (currRaw.isAssignableFrom(serClass)) { // specialization, ok as well
type = tf.constructSpecializedType(type, serClass);
} else {
throw new JsonMappingException(null,
String.format("Can not refine serialization type %s into %s; types not related",
type, serClass.getName()));
}
} catch (IllegalArgumentException iae) {
throw new JsonMappingException(null,
String.format("Failed to widen type %s with annotation (value %s), from '%s': %s",
Expand All @@ -835,8 +844,20 @@ public JavaType refineSerializationType(final MapperConfig<?> config,
if (keyType.hasRawClass(keyClass)) {
keyType = keyType.withStaticTyping();
} else {
Class<?> currRaw = keyType.getRawClass();
try {
keyType = tf.constructGeneralizedType(keyType, keyClass);
// 19-May-2016, tatu: As per [databind#1231], [databind#1178] may need to actually
// specialize (narrow) type sometimes, even if more commonly opposite
// is needed.
if (keyClass.isAssignableFrom(currRaw)) { // common case
keyType = tf.constructGeneralizedType(keyType, keyClass);
} else if (currRaw.isAssignableFrom(keyClass)) { // specialization, ok as well
keyType = tf.constructSpecializedType(keyType, keyClass);
} else {
throw new JsonMappingException(null,
String.format("Can not refine serialization key type %s into %s; types not related",
keyType, keyClass.getName()));
}
} catch (IllegalArgumentException iae) {
throw new JsonMappingException(null,
String.format("Failed to widen key type of %s with concrete-type annotation (value %s), from '%s': %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void testBrokenAnnotation() throws Exception
try {
serializeAsString(MAPPER, new BrokenClass());
} catch (Exception e) {
verifyException(e, "not a super-type of");
verifyException(e, "types not related");
}
}

Expand Down

0 comments on commit ebadfd2

Please sign in to comment.