Serializer started
This commit is contained in:
parent
afafe62cf6
commit
791589821b
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.alterdekim.game</groupId>
|
||||
<artifactId>actionScriptDecompiler</artifactId>
|
||||
<version>0.0.6</version>
|
||||
<version>0.0.7</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>SWFDissect</name>
|
||||
|
@ -7,14 +7,45 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
public class FlashMapper {
|
||||
|
||||
public static <T> Map<String, Object> objToMap(List<T> l) {
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
for( T o : l ) {
|
||||
try {
|
||||
Map<String, Object> m1 = new HashMap<>();
|
||||
String s = getId(o).toString();
|
||||
List<Field> fields = Arrays.stream(o.getClass().getDeclaredFields())
|
||||
.filter(f -> f.isAnnotationPresent(FlashField.class))
|
||||
.collect(Collectors.toList());
|
||||
for (Field f : fields) {
|
||||
String key = f.getAnnotation(FlashField.class).name();
|
||||
Object val = f.get(o);
|
||||
m1.put(key, val);
|
||||
}
|
||||
m.put(s, m1);
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("FlashMapper valueGet error: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
private static <T> Long getId(T o) throws IllegalAccessException {
|
||||
Optional<Field> idField = Arrays.stream(o.getClass().getDeclaredFields())
|
||||
.filter(f -> f.isAnnotationPresent(FlashValue.class) &&
|
||||
f.getAnnotation(FlashValue.class).type() == FlashValueType.Id)
|
||||
.findFirst();
|
||||
if( idField.isEmpty() ) return 0L;
|
||||
Field f = idField.get();
|
||||
f.setAccessible(true);
|
||||
return (Long) f.get(o);
|
||||
}
|
||||
|
||||
public static <T> T mapToObj(Map<String, Object> m, Class<T> obj) {
|
||||
try {
|
||||
T result = obj.getDeclaredConstructor().newInstance();
|
||||
|
Loading…
x
Reference in New Issue
Block a user