com.thoughtworks.xstream.annotations.XStreamImplicit Java Examples

The following examples show how to use com.thoughtworks.xstream.annotations.XStreamImplicit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processImplicitAnnotation(final Field field) {
    final XStreamImplicit implicitAnnotation = field.getAnnotation(XStreamImplicit.class);
    if (implicitAnnotation != null) {
        if (implicitCollectionMapper == null) {
            throw new InitializationException("No "
                + ImplicitCollectionMapper.class.getName()
                + " available");
        }
        final String fieldName = field.getName();
        final String itemFieldName = implicitAnnotation.itemFieldName();
        final String keyFieldName = implicitAnnotation.keyFieldName();
        boolean isMap = Map.class.isAssignableFrom(field.getType());
        Class itemType = null;
        if (!field.getType().isArray()) {
            final Type genericType = field.getGenericType();
            if (genericType instanceof ParameterizedType) {
                final Type[] actualTypeArguments = ((ParameterizedType)genericType)
                    .getActualTypeArguments();
                final Type typeArgument = actualTypeArguments[isMap ? 1 : 0];
                itemType = getClass(typeArgument);
            }
        }
        if (isMap) {
            implicitCollectionMapper.add(
                field.getDeclaringClass(), fieldName,
                itemFieldName != null && !"".equals(itemFieldName) ? itemFieldName : null,
                itemType, keyFieldName != null && !"".equals(keyFieldName)
                    ? keyFieldName
                    : null);
        } else {
            if (itemFieldName != null && !"".equals(itemFieldName)) {
                implicitCollectionMapper.add(
                    field.getDeclaringClass(), fieldName, itemFieldName, itemType);
            } else {
                implicitCollectionMapper
                    .add(field.getDeclaringClass(), fieldName, itemType);
            }
        }
    }
}