}
@SuppressWarnings("unchecked")
private <T> Codec<T> createCodec(Class<T> type, ResolverContext context,
AnnotatedElement metadata) {
BoundObject settings = metadata.getAnnotation(BoundObject.class);
// TODO: Handle type incompatibility
if (Void.class.equals(settings.type())) {
if (settings.selectFrom().alternatives().length > 0
|| settings.selectFrom().defaultType() != Void.class) {
return (Codec<T>) new SelectFromCodec(type, settings
.selectFrom(), context, codecFactory,
hideChoices(metadata));
}
if (settings.types().length == 0) {
return createCodec(type, context);
}
List<Codec<?>> codecs = new ArrayList<Codec<?>>();
for (Class valueType : settings.types()) {
codecs.add(codecFactory.create(null, valueType, context));
}
CodecSelectorFactory selectorFactory = null;
selectorFactory = new TypePrefixSelectorFactory();
CodecSelector selector = selectorFactory.create(context, codecs);
return (Codec<T>) new SwitchingCodec(selector);
} else {
return (Codec<T>) createCodec(settings.type(), context);
}
}