in jackson/src/java/org/apache/fulcrum/json/jackson/JacksonMapperService.java [403:491]
public void initialize() throws Exception {
mapper = new ObjectMapper();
Enumeration<String> enumKey = annotationInspectors.keys();
while (enumKey.hasMoreElements()) {
String key = enumKey.nextElement();
String avClass = annotationInspectors.get(key);
if (key.equals("primary") && avClass != null) {
try {
primary = (AnnotationIntrospector) Class.forName(avClass).getConstructor()
.newInstance();
} catch (Exception e) {
throw new InstantiationException(
"JsonMapperService: Error instantiating " + avClass
+ " for " + key);
}
} else if (key.equals("secondary") && avClass != null) {
try {
secondary = (AnnotationIntrospector) Class.forName(avClass).getConstructor()
.newInstance();
} catch (Exception e) {
throw new InstantiationException(
"JsonMapperService: Error instantiating " + avClass
+ " for " + key);
}
}
}
if (primary == null) {
primary = new JacksonAnnotationIntrospector(); // support default
getLogger().info(
"using default introspector:"
+ primary.getClass().getName());
mapper.setAnnotationIntrospector(primary);
} else {
AnnotationIntrospector pair = new AnnotationIntrospector.Pair(
primary, secondary);
mapper.setAnnotationIntrospector(pair);
}
// mapper.enableDefaultTypingAsProperty(DefaultTyping.OBJECT_AND_NON_CONCRETE,
// "type");
if (features != null) {
Enumeration<String> enumFeatureKey = features.keys();
while (enumFeatureKey.hasMoreElements()) {
String featureKey = enumFeatureKey.nextElement();
Boolean featureValue = features.get(featureKey);
Feature feature;
if (featureKey != null && featureValue != null) {
try {
String[] featureParts = featureKey.split("\\.");
getLogger().info(
"initializing mapper feature: "
+ featureParts[featureParts.length - 1]
+ " with " + featureValue);
feature = Feature
.valueOf(featureParts[featureParts.length - 1]);
mapper.configure(feature, featureValue);
assert mapper.getSerializationConfig().isEnabled(
feature) == featureValue;
} catch (Exception e) {
throw new AssertionError(
"JsonMapperService: Error instantiating feature "
+ featureKey + " with " + featureValue,
e);
}
}
}
}
if (defaultTypeDefs != null && defaultTypeDefs.length == 2) {
DefaultTyping defaultTyping = DefaultTyping
.valueOf(defaultTypeDefs[0]);
mapper.enableDefaultTypingAsProperty(defaultTyping,
defaultTypeDefs[1]);
getLogger().info(
"default typing is " + defaultTypeDefs[0] + " with key:"
+ defaultTypeDefs[1]);
}
getLogger().info("setting date format to:" + dateFormat);
getLogger().info("keepFilters is:" + cacheFilters);
mapper.setDateFormat(new SimpleDateFormat(dateFormat));
filters = Collections
.synchronizedMap(new HashMap<String, FilterProvider>());
getLogger().info("initialized: mapper:" + mapper);
}