| 1 | |
package com.buckosoft.PicMan.service.support; |
| 2 | |
|
| 3 | |
import java.util.Collection; |
| 4 | |
|
| 5 | |
import com.fasterxml.jackson.databind.AnnotationIntrospector; |
| 6 | |
import com.fasterxml.jackson.databind.BeanDescription; |
| 7 | |
import com.fasterxml.jackson.databind.JavaType; |
| 8 | |
import com.fasterxml.jackson.databind.SerializationConfig; |
| 9 | |
import com.fasterxml.jackson.databind.introspect.AnnotatedClass; |
| 10 | |
import com.fasterxml.jackson.databind.jsontype.NamedType; |
| 11 | |
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder; |
| 12 | |
import com.fasterxml.jackson.databind.jsontype.TypeSerializer; |
| 13 | |
|
| 14 | |
public class JsonUtils { |
| 15 | |
|
| 16 | 0 | private JsonUtils() { |
| 17 | 0 | } |
| 18 | |
|
| 19 | |
public static TypeSerializer createTypeSerializer( |
| 20 | |
SerializationConfig config, JavaType baseType) { |
| 21 | 0 | BeanDescription bean = config.introspectClassAnnotations(baseType |
| 22 | 0 | .getRawClass()); |
| 23 | 0 | AnnotatedClass ac = bean.getClassInfo(); |
| 24 | 0 | AnnotationIntrospector ai = config.getAnnotationIntrospector(); |
| 25 | 0 | TypeResolverBuilder<?> b = ai.findTypeResolver(config, ac, baseType); |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 0 | Collection<NamedType> subtypes = null; |
| 31 | 0 | if (b == null) { |
| 32 | 0 | b = config.getDefaultTyper(baseType); |
| 33 | |
} else { |
| 34 | 0 | subtypes = config.getSubtypeResolver().collectAndResolveSubtypes( |
| 35 | |
ac, config, ai); |
| 36 | |
} |
| 37 | |
|
| 38 | 0 | if (b == null) { |
| 39 | 0 | return null; |
| 40 | |
} |
| 41 | 0 | return b.buildTypeSerializer(config, baseType, subtypes); |
| 42 | |
} |
| 43 | |
} |