本文整理汇总了Java中com.thoughtworks.xstream.annotations.XStreamAlias类的典型用法代码示例。如果您正苦于以下问题:Java XStreamAlias类的具体用法?Java XStreamAlias怎么用?Java XStreamAlias使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XStreamAlias类属于com.thoughtworks.xstream.annotations包,在下文中一共展示了XStreamAlias类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: xmlBean2Map
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
private Map<String, String> xmlBean2Map(Object bean) {
Map<String, String> result = Maps.newHashMap();
for (Entry<String, Reflect> entry : Reflect.on(bean).fields().entrySet()) {
Reflect reflect = entry.getValue();
if (reflect.get() == null) {
continue;
}
try {
Field field = bean.getClass().getDeclaredField(entry.getKey());
if (field.isAnnotationPresent(XStreamAlias.class)) {
result.put(field.getAnnotation(XStreamAlias.class).value(),
reflect.get().toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
示例2: existsCDATA
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
/**
* 功能描述:检查字段是否存在XStreamCDATA标签
*
* @param clazz
* 属性类型
* @param fieldAlias
* XStream 属性名称
* @return boolean 是否
*/
private static boolean existsCDATA(Class<?> clazz, String fieldAlias) {
// scan fields
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
// 1. exists XStreamCDATA
if (null != field.getAnnotation(XStream2Field.class)) {
XStreamAlias xStreamAlias = field
.getAnnotation(XStreamAlias.class);
// 2. exists XStreamAlias
if (null != xStreamAlias) {
if (fieldAlias.equals(xStreamAlias.value()))// matched
return true;
} else {// not exists XStreamAlias
if (fieldAlias.equals(field.getName()))
return true;
}
}
}
return false;
}
示例3: loadXML
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
public static SPStoryWorldData loadXML(File xmlFile) throws FileNotFoundException {
FileReader reader = new FileReader(xmlFile);
XStream xstream = new XStream(new DomDriver());
xstream.autodetectAnnotations(true);
xstream.alias(SPStoryWorldData.class.getAnnotation(XStreamAlias.class).value(), SPStoryWorldData.class);
Object obj = xstream.fromXML(reader);
try {
reader.close();
} catch (IOException e) {
}
if (!(obj instanceof SPStoryWorldData)) throw new RuntimeException("file " + xmlFile.getAbsolutePath() + " doesn't contain a xml with SPStoryWorldData");
SPStoryWorldData data = (SPStoryWorldData) obj;
data.file = xmlFile.getAbsolutePath();
return data;
}
示例4: processAliasAnnotation
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
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
}
}
}
}
示例5: test
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
public void test() throws NoSuchFieldException, SecurityException {
WxSendRedpackRequest request = new WxSendRedpackRequest();
request.setMchBillno("123");
request.setActName("ab");
for (Entry<String, Reflect> entry : Reflect.on(request).fields().entrySet()) {
Reflect reflect = entry.getValue();
if (reflect.get() == null) {
continue;
}
Field field = WxSendRedpackRequest.class.getDeclaredField(entry.getKey());
if (field.isAnnotationPresent(XStreamAlias.class)) {
System.err.println(reflect.get() + " = " + field.getAnnotation(XStreamAlias.class).value());
}
}
}
示例6: processAliasAnnotation
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
private void processAliasAnnotation(Class<?> paramClass, Set<Class<?>> paramSet)
{
XStreamAlias localXStreamAlias = (XStreamAlias)paramClass.getAnnotation(XStreamAlias.class);
if (localXStreamAlias != null)
{
if (this.classAliasingMapper == null)
throw new InitializationException("No " + ClassAliasingMapper.class.getName() + " available");
this.classAliasingMapper.addClassAlias(localXStreamAlias.value(), paramClass);
if (localXStreamAlias.impl() != Void.class)
{
this.defaultImplementationsMapper.addDefaultImplementation(localXStreamAlias.impl(), paramClass);
if (paramClass.isInterface())
paramSet.add(localXStreamAlias.impl());
}
}
}
示例7: getFieldMap
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
private Map<String, Field> getFieldMap(List<Field> fields) {
Map<String, Field> fieldMap = 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();
}
});
return fieldMap;
}
示例8: xmlBean2Map
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
/**
* 将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()));
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());
}
field.setAccessible(isAccessible);
} catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
return result;
}
示例9: processFieldAliasAnnotation
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
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());
}
}
示例10: xmlBean2Map
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
/**
* 将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()));
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;
}
示例11: processFieldAliasAnnotation
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
private void processFieldAliasAnnotation(Field paramField)
{
XStreamAlias localXStreamAlias = (XStreamAlias)paramField.getAnnotation(XStreamAlias.class);
if (localXStreamAlias != null)
{
if (this.fieldAliasingMapper == null)
throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available");
this.fieldAliasingMapper.addFieldAlias(localXStreamAlias.value(), paramField.getDeclaringClass(), paramField.getName());
}
}
示例12: isReadable
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return type.getAnnotation(XStreamAlias.class) != null || isXtreamable(genericType);
}
示例13: isWriteable
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return type.getAnnotation(XStreamAlias.class) != null || isXtreamable(genericType);
}
示例14: isXtreamable
import com.thoughtworks.xstream.annotations.XStreamAlias; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
private boolean isXtreamable(Type genericType) {
return (genericType instanceof Class && ((Class) genericType).getAnnotation(XStreamAlias.class) != null);
}