確かに、私はこれらすべてのJavaにまったく慣れていないので、質問があります。WCFサービスで取得した応答を逆シリアル化しようとしていますが、すべて正常に機能しますが、これを行うための汎用関数を作成しようとしています。 。
基本的に私がしていることは
public List<msg> GetService(String method){
List<msg> response = new ArrayList<msg>();
Type msgType = new TypeToken<List<msg>>(){}.getType();
//Obtaining result
response = uJSON.fromJson(serviceResponse, msgType);
//uJSON is an instance of Gson library, for deserializing it just needs
//the service response and a Class<T> or Type to reflect the obtained message
}
私がやろうとしているのは、Type "msg"ジェネリックを取得することです。つまり、...
public <thing> void GetInstanceService(String method){
List<thing> response = new ArrayList<thing>();
Type rType2 = new TypeToken<List<thing>>(){}.getType(); //Got java.util.List<thing>
//And when I'm trying to deserialize I just obtain a List of object
//[java.lang.Object@5c7a987e, java.lang.Object@74b1a7a0]
type2 = uJSON.fromJson(new String(entity), rType2);
}
しかし、私はこのように呼んでいます。
comm.<msgType>GetInstanceService("listTestType");
したがって、「GetInstanceService」を呼び出すと、「thing」は「msgType」タイプに
なります。また、応答は?の代わりにList<thing>
すべきではありません。List<msgType>
List <Object>
さらに、「Type」パラメータを介して型を明示的に渡そうとすると、このようなコンパイル時エラーが発生します。
public void GetInstanceService(Type type){
List<type> type2 = new ArrayList<type>(); //Compilation time error
//Or
msgType oType = new msgType();
Class classType = oType.getClass();
List<classType> type3; //Compilation time error
}
それで、これらの試みのどれも効果的でなかった場合、どうすれば逆シリアル化のタイプを設定できますか?