だから私はJacksonを使ってオブジェクトをJSONに変換し、それを接続を介して送信し、接続の反対側にあるオブジェクトに変換し直しています。JSONを読み取ってJAVAオブジェクトに変換しようとすると、JSONが複数のオブジェクトに正常に変更されるという問題が発生しました。例で見た方が簡単です。
ObjectMapper map = new ObjectMapper();
Boolean test1 = null;
String test2 = null;
Integer test3 = null;
Boolean obj = false;
byte[] bytes = null;
try {
bytes = map.writeValueAsBytes(obj);
} catch (Exception e) {
e.printStackTrace();
}
try {
test1 = map.readValue(bytes, Boolean.class);
test2 = map.readValue(bytes, String.class);
test3 = map.readValue(bytes, Integer.class);
} catch (Exception e)
{
System.out.println("FAILED");
}
System.out.println("test1: " + test1 + "\ntest2: " + test2 + "\ntest3: " + test3);
そして出力:
失敗したtest1:false test2:false test3:null
JSONブール値を文字列に変換しようとすると成功しました。これは、現在のメソッドが以下のようになり、オブジェクトの逆シリアル化のタイプが間違っていると、問題が発生するため、問題があります。
public void JSONtoJAVA(Class<?> clazz)
{
for(Event event : Events)
{
try
{
Object deserialized = map.readValue(bytes, event.getC());
Event.getMethod().invoke(deserialized);
}
catch(Exception e)
{
//Failed ignore
}
}
}
あなたの助けに感謝します!