Skip to content

Commit ae82a53

Browse files
committed
Fix a problem that results in FasterXML/jackson-module-jsonSchema#34
1 parent 1b86c85 commit ae82a53

File tree

2 files changed

+9
-33
lines changed

2 files changed

+9
-33
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,7 @@ public void depositSchemaProperty(ObjectNode propertiesNode, SerializerProvider
628628
// Maybe it already has annotated/statically configured serializer?
629629
JsonSerializer<Object> ser = getSerializer();
630630
if (ser == null) { // nope
631-
Class<?> serType = getRawSerializationType();
632-
if (serType == null) {
633-
serType = getPropertyType();
634-
}
635-
ser = provider.findValueSerializer(serType, this);
631+
ser = provider.findValueSerializer(getType(), this);
636632
}
637633
boolean isOptional = !isRequired();
638634
if (ser instanceof SchemaAware) {

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

+8-28
Original file line numberDiff line numberDiff line change
@@ -204,28 +204,8 @@ protected abstract void serializeContents(T value, JsonGenerator jgen, Serialize
204204
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
205205
throws JsonMappingException
206206
{
207-
/* 15-Jan-2010, tatu: This should probably be rewritten, given that
208-
* more information about content type is actually being explicitly
209-
* passed. So there should be less need to try to re-process that
210-
* information.
211-
*/
212207
ObjectNode o = createSchemaNode("array", true);
213-
JavaType contentType = null;
214-
if (typeHint != null) {
215-
JavaType javaType = provider.constructType(typeHint);
216-
contentType = javaType.getContentType();
217-
if (contentType == null) { // could still be parametrized (Iterators)
218-
if (typeHint instanceof ParameterizedType) {
219-
Type[] typeArgs = ((ParameterizedType) typeHint).getActualTypeArguments();
220-
if (typeArgs.length == 1) {
221-
contentType = provider.constructType(typeArgs[0]);
222-
}
223-
}
224-
}
225-
}
226-
if (contentType == null && _elementType != null) {
227-
contentType = _elementType;
228-
}
208+
JavaType contentType = _elementType;
229209
if (contentType != null) {
230210
JsonNode schemaNode = null;
231211
// 15-Oct-2010, tatu: We can't serialize plain Object.class; but what should it produce here? Untyped?
@@ -249,16 +229,16 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
249229
{
250230
JsonArrayFormatVisitor arrayVisitor = (visitor == null) ? null : visitor.expectArrayFormat(typeHint);
251231
if (arrayVisitor != null) {
252-
TypeFactory tf = visitor.getProvider().getTypeFactory();
253-
JavaType contentType = tf.moreSpecificType(_elementType, typeHint.getContentType());
254-
if (contentType == null) {
255-
throw new JsonMappingException("Could not resolve type");
256-
}
232+
/* 01-Sep-2014, tatu: Earlier was trying to make use of 'typeHint' for some
233+
* reason, causing NPE (as per https://github.com/FasterXML/jackson-module-jsonSchema/issues/34)
234+
* if coupled with `@JsonValue`. But I can't see much benefit of trying to rely
235+
* on TypeHint here so code is simplified like so:
236+
*/
257237
JsonSerializer<?> valueSer = _elementSerializer;
258238
if (valueSer == null) {
259-
valueSer = visitor.getProvider().findValueSerializer(contentType, _property);
239+
valueSer = visitor.getProvider().findValueSerializer(_elementType, _property);
260240
}
261-
arrayVisitor.itemsFormat(valueSer, contentType);
241+
arrayVisitor.itemsFormat(valueSer, _elementType);
262242
}
263243
}
264244

0 commit comments

Comments
 (0)