Conversion SQLElement en Json + Gestion des exceptions dans TCPServer
- SQLElement et SQLElementList incluent une méthode permettant la conversion en JsonEement - Meilleure gestion des exceptions dans TCPServer lors du traitement d'un packet reçu
This commit is contained in:
parent
0df60d9d01
commit
823c319c2b
@ -17,6 +17,9 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import fr.pandacube.java.util.Log;
|
||||
import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator;
|
||||
|
||||
@ -393,5 +396,15 @@ public abstract class SQLElement<E extends SQLElement<E>> {
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public JsonObject asJsonObject() {
|
||||
JsonObject json = new JsonObject();
|
||||
for (SQLField<E, ?> f : getFields().values()) {
|
||||
json.add(f.name, new Gson().toJsonTree(get(f)));
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
import fr.pandacube.java.util.Log;
|
||||
|
||||
/**
|
||||
@ -162,5 +164,12 @@ public class SQLElementList<E extends SQLElement<E>> extends ArrayList<E> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public JsonArray asJsonArray() {
|
||||
JsonArray json = new JsonArray();
|
||||
forEach(el -> json.add(el.asJsonObject()));
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -235,11 +235,7 @@ public class TCPServer extends Thread implements Closeable {
|
||||
|
||||
PacketClient pc = (PacketClient) p;
|
||||
|
||||
try {
|
||||
listener.onPacketReceive(this, co, pc);
|
||||
} catch(Exception e) {
|
||||
Log.severe("Exception while calling TCPServerListener.onPacketReceive()", e);
|
||||
}
|
||||
listener.onPacketReceive(this, co, pc);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user