Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows replacing of the schema serializer #4018

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@

public class ObjectMapperFactory {

private static SchemaSerializerFactory schemaSerializerFactory;

protected static ObjectMapper createJson() {
return create(null);
}
Expand Down Expand Up @@ -88,7 +90,7 @@ public void setupModule(SetupContext context) {
public JsonSerializer<?> modifySerializer(
SerializationConfig config, BeanDescription desc, JsonSerializer<?> serializer) {
if (Schema.class.isAssignableFrom(desc.getBeanClass())) {
return new SchemaSerializer((JsonSerializer<Object>) serializer);
return schemaSerializerFactory==null?new SchemaSerializer((JsonSerializer<Object>) serializer):schemaSerializerFactory.create(serializer);
}
return serializer;
}
Expand Down Expand Up @@ -162,5 +164,9 @@ public static ObjectMapper buildStrictGenericObjectMapper() {
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper;
}

public static void setSchemaSerializerFactory(SchemaSerializerFactory schemaSerializerFactory) {
ObjectMapperFactory.schemaSerializerFactory = schemaSerializerFactory;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.swagger.v3.core.util;

import com.fasterxml.jackson.databind.JsonSerializer;

import io.swagger.v3.core.jackson.SchemaSerializer;

public interface SchemaSerializerFactory {

SchemaSerializer create(JsonSerializer<?> serializer);

}