I am currently trying to take apart a objekt with logic like this
public String toString(Object x) throws IllegalArgumentException, IllegalAccessException {
if(i > 10000) {
throw new StackOverflowError("The Deserilesation of an objekt has overflowen");
}
i++;
if(x instanceof String) {
return String.valueOf(x);
}else if(x instanceof Integer) {
return String.valueOf(x);
}else if(x instanceof Boolean) {
return String.valueOf(x);
}else if(x instanceof Long) {
return String.valueOf(x);
}else if(x instanceof Float) {
return String.valueOf(x);
}else if(x instanceof Double){
return String.valueOf(x);
}else if(x instanceof Byte){
return String.valueOf(x);
}else if(x instanceof Character){
return String.valueOf(x);
}else {
String toreturn = "{";
for(Field f : x.getClass().getDeclaredFields()) {
f.setAccessible(true);
try {
toreturn += f.getName() + ":"+ toString(f.get(x)) + " ";
}catch (NullPointerException e) {
toreturn += f.getName() + ":Null ";
}
}
toreturn += "}";
return toreturn;
}
but if there is a int[]
then i will get the standert tostring like 00000@000000, my question how can i deteckt that i have an array, i tryed if(x instanceof Array)
but there is not array class
Aucun commentaire:
Enregistrer un commentaire