com.thoughtworks.xstream.annotations.XStreamAlias Java Examples

The following examples show how to use com.thoughtworks.xstream.annotations.XStreamAlias. 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 6 votes vote down vote up
private void processAliasAnnotation(final Class<?> type, final Set<Class<?>> types) {
    final XStreamAlias aliasAnnotation = type.getAnnotation(XStreamAlias.class);
    if (aliasAnnotation != null) {
        if (classAliasingMapper == null) {
            throw new InitializationException("No "
                + ClassAliasingMapper.class.getName()
                + " available");
        }
        classAliasingMapper.addClassAlias(aliasAnnotation.value(), type);
        if (aliasAnnotation.impl() != Void.class) {
            // Alias for Interface/Class with an impl
            defaultImplementationsMapper.addDefaultImplementation(
                aliasAnnotation.impl(), type);
            if (type.isInterface()) {
                types.add(aliasAnnotation.impl()); // alias Interface's impl
            }
        }
    }
}
 
Example #2
Source File: XStreamUtils.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public boolean allows(Class type) {
    if (type == null) {
        return false;
    } else {
        return type.isAnnotationPresent( XStreamAlias.class) || type.isAnnotationPresent( XStreamAliasType.class) || type.isAnnotationPresent( XStreamInclude.class);
    }
}
 
Example #3
Source File: WxPayOrderNotifyResultConverter.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
private Map<String, Field> getFieldMap(List<Field> fields) {
  return Maps.uniqueIndex(fields, new Function<Field, String>() {
    @Override
    public String apply(Field field) {
      if (field.isAnnotationPresent(XStreamAlias.class)) {
        return field.getAnnotation(XStreamAlias.class).value();
      }
      return field.getName();
    }
  });
}
 
Example #4
Source File: SignUtils.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
/**
 * 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象
 *
 * @param bean 包含@XStreamAlias的xml bean对象
 * @return map对象
 */
public static Map<String, String> xmlBean2Map(Object bean) {
  Map<String, String> result = Maps.newHashMap();
  List<Field> fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields()));
  fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields()));
  if(bean.getClass().getSuperclass().getSuperclass() == BaseWxPayRequest.class){
    fields.addAll(Arrays.asList(BaseWxPayRequest.class.getDeclaredFields()));
  }

  if(bean.getClass().getSuperclass().getSuperclass() == BaseWxPayResult.class){
    fields.addAll(Arrays.asList(BaseWxPayResult.class.getDeclaredFields()));
  }

  for (Field field : fields) {
    try {
      boolean isAccessible = field.isAccessible();
      field.setAccessible(true);
      if (field.get(bean) == null) {
        field.setAccessible(isAccessible);
        continue;
      }

      if (field.isAnnotationPresent(XStreamAlias.class)) {
        result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString());
      } else if (!Modifier.isStatic(field.getModifiers())) {
        //忽略掉静态成员变量
        result.put(field.getName(), field.get(bean).toString());
      }

      field.setAccessible(isAccessible);
    } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
      log.error(e.getMessage(), e);
    }

  }

  return result;
}
 
Example #5
Source File: AnnotationMapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processFieldAliasAnnotation(final Field field) {
    final XStreamAlias aliasAnnotation = field.getAnnotation(XStreamAlias.class);
    if (aliasAnnotation != null) {
        if (fieldAliasingMapper == null) {
            throw new InitializationException("No "
                + FieldAliasingMapper.class.getName()
                + " available");
        }
        fieldAliasingMapper.addFieldAlias(
            aliasAnnotation.value(), field.getDeclaringClass(), field.getName());
    }
}