mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2025-07-18 15:59:24 +00:00
[VRAC] Corrections de bug #1/?
Bug détectés restants : - MainFrame pas mise à jour avec le compte utilisateur connecté lorsqu'on switch dessus depuis la StartFrame - Le serveur renvoie REFUSED_QUERY lorsqu'on tente de se déconnecter
This commit is contained in:
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -20,13 +21,55 @@ public class GSonMessageToolFactory implements IMessageToolFactory {
|
||||
return (obj)->gson.toJson(obj);
|
||||
}
|
||||
public <T> IObjectParser<T> getObjectParser(Class<T> clazz){
|
||||
return (str)->gson.fromJson(str, clazz);
|
||||
return (str)->gson.fromJson(str, new Element<>(clazz));
|
||||
}
|
||||
public <T> IObjectFormatter<List<T>> getListFormatter(Class<T> clazz){
|
||||
return (obj)->gson.toJson(obj);
|
||||
}
|
||||
public <T> IObjectParser<List<T>> getListParser(Class<T> clazz){
|
||||
Type listType = new TypeToken<ArrayList<T>>(){}.getType();
|
||||
return (str)->gson.fromJson(str, listType);
|
||||
//Type listType = new TypeToken<ArrayList<T>>(){}.getType();
|
||||
return (str)->gson.fromJson(str, new ListWithElements<>(clazz));
|
||||
}
|
||||
|
||||
private class Element<T> implements ParameterizedType {
|
||||
|
||||
private Class<T> cl;
|
||||
|
||||
public Element(Class<T> cl) {
|
||||
this.cl = cl;
|
||||
}
|
||||
|
||||
public Type[] getActualTypeArguments() {
|
||||
return new Type[] {cl};
|
||||
}
|
||||
|
||||
public Type getRawType() {
|
||||
return cl;
|
||||
}
|
||||
|
||||
public Type getOwnerType() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class ListWithElements<T> implements ParameterizedType {
|
||||
|
||||
private Class<T> elementsClass;
|
||||
|
||||
public ListWithElements(Class<T> elementsClass) {
|
||||
this.elementsClass = elementsClass;
|
||||
}
|
||||
|
||||
public Type[] getActualTypeArguments() {
|
||||
return new Type[] {elementsClass};
|
||||
}
|
||||
|
||||
public Type getRawType() {
|
||||
return List.class;
|
||||
}
|
||||
|
||||
public Type getOwnerType() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user