me.chanjar.weixin.common.util.xml.LongArrayConverter Maven / Gradle / Ivy
The newest version!
package me.chanjar.weixin.common.util.xml;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.thoughtworks.xstream.converters.basic.StringConverter;
/**
* Long型数组转换器.
*
* @author Binary Wang
* created on 2019-08-22
*/
public class LongArrayConverter extends StringConverter {
@Override
public boolean canConvert(Class type) {
return type == Long[].class;
}
@Override
public String toString(Object obj) {
return "";
}
@Override
public Object fromString(String str) {
final Iterable iterable = Splitter.on(",").split(str);
final String[] strings = Iterables.toArray(iterable, String.class);
Long[] result = new Long[strings.length];
int index = 0;
for (String string : strings) {
result[index++] = Long.parseLong(string);
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy