1

Genson のホームページにリストされている機能の 1 つは、「複雑なキーを使用したマップのシリアライズとデシリアライズ」です。

Keys を含むマップを複雑な Java オブジェクトとして json 文字列にシリアル化し、それらを逆シリアル化して Java Map に戻そうとしています。デシリアライズされたマップ キーは常に文字列です。このような複雑なキーマップのシリアライゼーションとデシリアライゼーションにgensonを使用する方法を教えてください。

これが私のコードです

    Genson genson = new GensonBuilder().useClassMetadata(true).useRuntimeType(true).create();
    VO vo = new VO();
    Key key = new Key(18314212, new Timestamp(System.currentTimeMillis()),new Timestamp(System.currentTimeMillis()));
    vo.setEndTime(new Timestamp(System.currentTimeMillis()));
    vo.setStartTime(new Timestamp(System.currentTimeMillis()));
    vo.setItemID(18314212);
    vo.setKey(key);
    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put(key, vo);
    String json  = genson.serialize(map);
    System.out.println(json); //the json map key does not have @Class attribute 
    Map jsonMap =  genson.deserialize(json, Map.class);
    System.out.println(jsonMap);
4

1 に答える 1