Skip to content

Commit 3b577e4

Browse files
committed
Code review. Fixes #2625
1 parent dfadcfe commit 3b577e4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

springdoc-openapi-tests/springdoc-openapi-hateoas-tests/src/test/java/test/org/springdoc/api/app10/SpringDocApp10NotSpecifiedTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,23 @@
2222

2323
package test.org.springdoc.api.app10;
2424

25+
import java.lang.reflect.Field;
26+
import java.util.HashMap;
27+
import java.util.Iterator;
28+
import java.util.Map;
29+
import java.util.Map.Entry;
30+
31+
import com.fasterxml.jackson.databind.ObjectMapper;
32+
import com.fasterxml.jackson.databind.introspect.SimpleMixInResolver;
33+
import com.fasterxml.jackson.databind.type.ClassKey;
34+
import org.apache.commons.lang3.reflect.FieldUtils;
35+
import org.junit.jupiter.api.AfterEach;
36+
import org.junit.jupiter.api.BeforeEach;
2537
import org.junit.jupiter.api.Test;
38+
import org.springdoc.core.providers.ObjectMapperProvider;
2639
import org.springdoc.core.utils.Constants;
40+
41+
import org.springframework.beans.factory.annotation.Autowired;
2742
import org.springframework.boot.SpringBootConfiguration;
2843
import org.springframework.boot.autoconfigure.SpringBootApplication;
2944
import org.springframework.data.web.config.EnableSpringDataWebSupport;
@@ -35,6 +50,11 @@
3550

3651
public class SpringDocApp10NotSpecifiedTest extends AbstractSpringDocTest {
3752

53+
private final Map<ClassKey, Class<?>> springMixins = new HashMap<>();
54+
55+
@Autowired
56+
ObjectMapperProvider objectMapperProvider;
57+
3858
@Override
3959
@Test
4060
public void testApp() throws Exception {
@@ -49,4 +69,29 @@ public static class SpringDocTestApp {
4969

5070
}
5171

72+
@BeforeEach
73+
void init() throws IllegalAccessException {
74+
Field convertersField2 = FieldUtils.getDeclaredField(ObjectMapper.class, "_mixIns", true);
75+
SimpleMixInResolver _mixIns = (SimpleMixInResolver) convertersField2.get(objectMapperProvider.jsonMapper());
76+
Field convertersField3 = FieldUtils.getDeclaredField(SimpleMixInResolver.class, "_localMixIns", true);
77+
Map<ClassKey, Class<?>> _localMixIns = (Map<ClassKey, Class<?>>) convertersField3.get(_mixIns);
78+
Iterator<Entry<ClassKey, Class<?>>> it = _localMixIns.entrySet().iterator();
79+
while (it.hasNext()) {
80+
Entry<ClassKey, Class<?>> entry = it.next();
81+
if (entry.getKey().toString().startsWith("org.springframework")) {
82+
springMixins.put(entry.getKey(), entry.getValue());
83+
it.remove();
84+
}
85+
}
86+
87+
}
88+
89+
@AfterEach
90+
void clean() throws IllegalAccessException {
91+
Field convertersField2 = FieldUtils.getDeclaredField(ObjectMapper.class, "_mixIns", true);
92+
SimpleMixInResolver _mixIns = (SimpleMixInResolver) convertersField2.get(objectMapperProvider.jsonMapper());
93+
Field convertersField3 = FieldUtils.getDeclaredField(SimpleMixInResolver.class, "_localMixIns", true);
94+
Map<ClassKey, Class<?>> _localMixIns = (Map<ClassKey, Class<?>>) convertersField3.get(_mixIns);
95+
_localMixIns.putAll(springMixins);
96+
}
5297
}

0 commit comments

Comments
 (0)