Skip to content

Commit 10ba2d4

Browse files
committed
Minor addition to JavaType (getContainedTypeOrUnknown()); fix a tiny potential problem with JsonValueSerializer contextualization
1 parent ad152e1 commit 10ba2d4

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/main/java/com/fasterxml/jackson/databind/JavaType.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.lang.reflect.Modifier;
44

55
import com.fasterxml.jackson.core.type.ResolvedType;
6+
import com.fasterxml.jackson.databind.type.TypeFactory;
67

78
/**
89
* Base class for type token classes used both to contain information
@@ -319,10 +320,37 @@ public boolean isConcrete() {
319320

320321
@Override
321322
public JavaType containedType(int index) { return null; }
322-
323+
323324
@Override
324325
public String containedTypeName(int index) { return null; }
325326

327+
/*
328+
/**********************************************************
329+
/* Extended API beyond ResolvedType
330+
/**********************************************************
331+
*/
332+
333+
// NOTE: not defined in Resolved type
334+
/**
335+
* Convenience method that is functionally same as:
336+
*<code>
337+
* JavaType t = containedType(index);
338+
* if (t == null) {
339+
* t = TypeFactory.unknownType();
340+
* }
341+
*</code>
342+
* and typically used to eliminate need for null checks for common case
343+
* where we just want to check if containedType is available first; and
344+
* if not, use "unknown type" (which translates to <code>java.lang.Object</code>
345+
* basically).
346+
*
347+
* @since 2.5
348+
*/
349+
public JavaType containedTypeOrUnknown(int index) {
350+
JavaType t = containedType(index);
351+
return (t == null) ? TypeFactory.unknownType() : t;
352+
}
353+
326354
/*
327355
/**********************************************************
328356
/* Semi-public API, accessing handlers

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public JsonSerializer<?> createContextual(SerializerProvider provider,
125125
* to serializer factory at this point...
126126
*/
127127
// 05-Sep-2013, tatu: I _think_ this can be considered a primary property...
128-
ser = provider.findPrimaryPropertySerializer(t, _property);
128+
ser = provider.findPrimaryPropertySerializer(t, property);
129129
/* 09-Dec-2010, tatu: Turns out we must add special handling for
130130
* cases where "native" (aka "natural") type is being serialized,
131131
* using standard serializer

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ public JsonNode getSchema(SerializerProvider provider, Type typeHint)
660660
// there's no way to statically determine the keys, so the "Entries" can't be determined.
661661
return o;
662662
}
663-
663+
664664
@Override
665665
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
666666
throws JsonMappingException

0 commit comments

Comments
 (0)