@Override public JavaType getContentType() { return _containerType.containedType(1); }
protected String nameForGenericType(JavaType type, Set<Options> options) { final StringBuilder generic = new StringBuilder(nameForClass(type, options)); final int count = type.containedTypeCount(); for (int i = 0; i < count; ++i) { final JavaType arg = type.containedType(i); final String argName = PrimitiveType.fromType(arg) != null ? nameForClass(arg, options) : nameForType(arg, options); generic.append(WordUtils.capitalize(argName)); } return generic.toString(); }
@Override public JavaType getInputType(TypeFactory typeFactory) { return _findConverterType(typeFactory).containedType(0); }
public static String name(JavaType type) { if (type instanceof ArrayType) { return "Array[" + name(type.getContentType()) + "]"; } else if (type instanceof CollectionLikeType) { return type.getRawClass().getSimpleName() + "[" + name(type.getContentType()) + "]"; } else if (type instanceof MapLikeType) { return "Map[" + name(type.getKeyType()) + ":" + name(type.getContentType()) + "]"; } else if (type instanceof SimpleType) { String name = type.getRawClass().getSimpleName(); StringBuilder args = new StringBuilder(); for (int i = 0; i < type.containedTypeCount(); i++) { args.append(name(type.containedType(i))).append(","); } if (args.length() > 0) { args.insert(0, '['); args.setCharAt(args.length() - 1, ']'); } return name + args; } return type.getRawClass().getSimpleName(); } }
@Override public JavaType getOutputType(TypeFactory typeFactory) { return _findConverterType(typeFactory).containedType(1); }
/** * Convenience method that is functionally same as: *<code> * JavaType t = containedType(index); * if (t == null) { * t = TypeFactory.unknownType(); * } *</code> * and typically used to eliminate need for null checks for common case * where we just want to check if containedType is available first; and * if not, use "unknown type" (which translates to <code>java.lang.Object</code> * basically). * * @since 2.5 */ public JavaType containedTypeOrUnknown(int index) { JavaType t = containedType(index); return (t == null) ? TypeFactory.unknownType() : t; }
@Override public JsonDeserializer<?> createContextual(final DeserializationContext deserializationContext, final BeanProperty property) throws JsonMappingException { final JavaType valueType = deserializationContext.getContextualType() .containedType(0); final CloseableIterableDeserializer deserializer = new CloseableIterableDeserializer(); deserializer.valueType = valueType; return deserializer; } }
/** * Method called to finalize setup of this deserializer, * when it is known for which property deserializer is needed for. */ @Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { KeyDeserializer kd = _keyDeserializer; if (kd == null) { kd = ctxt.findKeyDeserializer(_containerType.containedType(0), property); } else { if (kd instanceof ContextualKeyDeserializer) { kd = ((ContextualKeyDeserializer) kd).createContextual(ctxt, property); } } JsonDeserializer<?> vd = _valueDeserializer; vd = findConvertingContentDeserializer(ctxt, property, vd); JavaType contentType = _containerType.containedType(1); if (vd == null) { vd = ctxt.findContextualValueDeserializer(contentType, property); } else { // if directly assigned, probably not yet contextual, so: vd = ctxt.handleSecondaryContextualization(vd, property, contentType); } TypeDeserializer vtd = _valueTypeDeserializer; if (vtd != null) { vtd = vtd.forProperty(property); } return withResolved(kd, vtd, vd); }
wrapperKey = skipWrapperObject.value(); JavaType collectionType = property.getType(); JavaType collectedType = collectionType.containedType(0); wrappedType = collectedType.getRawClass(); return this;
@Override public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) { final JavaType javaType = _mapper.constructType(type.getType()); if (Pair.class.isAssignableFrom(javaType.getRawClass())) { final JavaType left = javaType.containedType(0); final String name = "MapOf" + WordUtils.capitalize(_typeName(left)); return new MapSchema() .name(name) .additionalProperties(context.resolve(new AnnotatedType(left))); } return super.resolve(type, context, chain); } }
return null; final JavaType left = javaType.containedType(0); Schema schema = context.resolve(new AnnotatedType().type(left).schemaProperty(type.isSchemaProperty())); String pName = null;
static boolean isResource(JavaType type) { return type.containedType(0).hasRawClass(Resource.class); }
if (_isOptionalType(type)) { AnnotatedType aType = new AnnotatedType() .type(type.containedType(0)) .ctxAnnotations(annotatedType.getCtxAnnotations()) .parent(annotatedType.getParent())
/** * Is this a {@literal Resources<Resource<?>>}? * * @param type * @return */ public static boolean isResourcesOfResource(JavaType type) { return Resources.class.isAssignableFrom(type.getRawClass()) && Resource.class.isAssignableFrom(type.containedType(0).getRawClass()); } }
/** * Navigate a chain of parametric types (e.g. Resources<Resource<String>>) until you find the innermost type (String). * * @param contentType * @return */ public static JavaType findRootType(JavaType contentType) { if (contentType.hasGenericTypes()) { return findRootType(contentType.containedType(0)); } else { return contentType; } }
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { if (_endpointDeserializer == null) { JavaType endpointType = _rangeType.containedType(0); if (endpointType == null) { // should this ever occur? endpointType = TypeFactory.unknownType(); } JsonDeserializer<Object> deser = ctxt.findContextualValueDeserializer(endpointType, property); return new RangeDeserializer(_rangeType, deser, _defaultBoundType); } return this; }
@Override public PagedResources deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JavaType rootType = JacksonHelper.findRootType(this.contentType); JavaType wrappedType = ctxt.getTypeFactory().constructParametricType(CollectionJsonDocument.class, rootType); CollectionJsonDocument<?> document = jp.getCodec().readValue(jp, wrappedType); List<Object> items = new ArrayList<>(); document.getCollection().getItems().forEach(item -> { Object data = item.toRawData(rootType); List<Link> links = item.getLinks() == null ? Collections.EMPTY_LIST : item.getLinks(); if (this.contentType.hasGenericTypes()) { if (this.contentType.containedType(0).hasRawClass(Resource.class)) { items.add(new Resource<>(data, potentiallyAddSelfLink(links, item.getHref()))); } else { items.add(data); } } }); PagedResources.PageMetadata pageMetadata = null; return new PagedResources(items, pageMetadata, potentiallyAddSelfLink(document.getCollection().getLinks(), document.getCollection().getHref())); }
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { if (visitor != null) { JsonObjectFormatVisitor objectVisitor = visitor.expectObjectFormat(typeHint); if (objectVisitor != null) { if (_endpointSerializer != null) { JavaType endpointType = _rangeType.containedType(0); JavaType btType = visitor.getProvider().constructType(BoundType.class); JsonSerializer<?> btSer = visitor.getProvider() .findValueSerializer(btType, null); objectVisitor.property("lowerEndpoint", _endpointSerializer, endpointType); objectVisitor.property("lowerBoundType", btSer, btType); objectVisitor.property("upperEndpoint", _endpointSerializer, endpointType); objectVisitor.property("upperBoundType", btSer, btType); } } } } }
/** * Returns true if the given type is one of {@code SIMPLE_TYPES} or an enum, or if the given type * is a {@link ValueProvider ValueProvider<T>} and {@code T} is one of {@code SIMPLE_TYPES} * or an enum. */ private static boolean isSimpleType(Class<?> type, JavaType genericType) { Class<?> unwrappedType = type.equals(ValueProvider.class) ? genericType.containedType(0).getRawClass() : type; return SIMPLE_TYPES.contains(unwrappedType) || unwrappedType.isEnum(); }
@Override public boolean canRead(final Type type, @Nullable final Class<?> contextClass, final MediaType mediaType) { final JavaType javaType = getJavaType(type, contextClass); if (Stream.class.isAssignableFrom(javaType.getRawClass())) { final JavaType containedType = javaType.containedType(0); return mapper.canDeserialize(containedType) && canRead(mediaType); } return false; }