Skip to content

Support Kotlin Serialization custom serializers #30870

@severn-everett

Description

@severn-everett

In KotlinSerializationSupport:

	@Nullable
	protected final KSerializer<Object> serializer(ResolvableType resolvableType) {
		Type type = resolvableType.getType();
		KSerializer<Object> serializer = serializerCache.get(type);
		if (serializer == null) {
			try {
				serializer = SerializersKt.serializerOrNull(type);
			}
			catch (IllegalArgumentException ignored) {
			}
			if (serializer != null) {
				if (hasPolymorphism(serializer.getDescriptor(), new HashSet<>())) {
					return null;
				}
				serializerCache.put(type, serializer);
			}
		}
		return serializer;
	}

the call serializer = SerializersKt.serializerOrNull(type); generates an instance of EmptySerializersModule() which - by definition - does not contain any information about custom serializers. Using format.getSerializersModule().serializerOrNull() would allow the Kotlin serialization in WebFlux to use custom serializers for third-party classes as is possible for WebMVC's Kotlin serialization implementation.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)theme: kotlinAn issue related to Kotlin supporttype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions