|
1 | 1 | package io.swagger.jackson;
|
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.databind.BeanDescription; |
3 | 4 | import com.fasterxml.jackson.databind.JavaType;
|
4 | 5 | import com.fasterxml.jackson.databind.ObjectMapper;
|
| 6 | +import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition; |
| 7 | +import com.fasterxml.jackson.databind.type.TypeFactory; |
5 | 8 | import io.swagger.converter.ModelConverterContextImpl;
|
6 | 9 | import io.swagger.models.Link;
|
7 | 10 | import io.swagger.models.Model;
|
8 | 11 | import io.swagger.models.ModelImpl;
|
9 | 12 | import io.swagger.models.Xml;
|
| 13 | +import io.swagger.models.properties.DecimalProperty; |
| 14 | +import io.swagger.models.properties.Property; |
10 | 15 | import org.testng.annotations.DataProvider;
|
11 | 16 | import org.testng.annotations.Test;
|
12 | 17 |
|
13 | 18 | import javax.xml.bind.annotation.XmlRootElement;
|
14 | 19 |
|
| 20 | +import java.lang.annotation.Annotation; |
| 21 | +import java.math.BigDecimal; |
| 22 | +import java.util.concurrent.atomic.AtomicReference; |
| 23 | + |
15 | 24 | import static org.testng.Assert.*;
|
16 | 25 |
|
17 | 26 | public class ModelResolverTest extends SwaggerTestBase {
|
@@ -51,4 +60,39 @@ public static class TypeWithNamespace {
|
51 | 60 | public static class TypeWithoutNamespace {
|
52 | 61 | }
|
53 | 62 |
|
| 63 | + @Test |
| 64 | + public void testResolvePropertyWithAtomicReference() { |
| 65 | + final ObjectMapper mapper = mapper(); |
| 66 | + final ModelResolver modelResolver = new ModelResolver(mapper); |
| 67 | + |
| 68 | + final JavaType javaType = TypeFactory.defaultInstance().constructType(TypeWithAtomicReferenceMember.class); |
| 69 | + final BeanDescription beanDescription = mapper.getSerializationConfig().introspect(javaType); |
| 70 | + |
| 71 | + JavaType atomicReferenceBigDecimalType = null; |
| 72 | + for (final BeanPropertyDefinition propDef : beanDescription.findProperties()) { |
| 73 | + if ("member".equals(propDef.getName())) { |
| 74 | + atomicReferenceBigDecimalType = propDef.getPrimaryType(); |
| 75 | + } |
| 76 | + } |
| 77 | + assertNotNull(atomicReferenceBigDecimalType, "Failed to read atomic reference field 'member'"); |
| 78 | + |
| 79 | + final Property actualProperty = modelResolver.resolveProperty(atomicReferenceBigDecimalType, |
| 80 | + new ModelConverterContextImpl(modelResolver), new Annotation[0], null); |
| 81 | + assertEquals(actualProperty.getType(), DecimalProperty.TYPE, "Got wrong type for AtomicReference member"); |
| 82 | + } |
| 83 | + |
| 84 | + @SuppressWarnings("unused") |
| 85 | + private static final class TypeWithAtomicReferenceMember { |
| 86 | + AtomicReference<BigDecimal> member; |
| 87 | + |
| 88 | + public AtomicReference<BigDecimal> getMember() { |
| 89 | + return member; |
| 90 | + } |
| 91 | + |
| 92 | + public void setMember(AtomicReference<BigDecimal> member) { |
| 93 | + this.member = member; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + |
54 | 98 | }
|
0 commit comments