1212import java .nio .ByteBuffer ;
1313import java .nio .ByteOrder ;
1414import java .util .ArrayList ;
15+ import java .util .HashMap ;
1516import java .util .List ;
1617
1718public class Transaction {
@@ -31,6 +32,7 @@ public class Transaction {
3132 public String signature ;
3233 public String signSignature ;
3334 public String vendorField ;
35+
3436 public String vendorFieldHex ;
3537
3638 public static Transaction deserialize (String serialized ) {
@@ -212,10 +214,52 @@ public String serialize() {
212214 }
213215
214216 public String toJson () {
217+
218+ HashMap <String , Object > map = new HashMap <String , Object >();
219+ map .put ("network" , this .network );
220+ map .put ("id" , this .id );
221+ map .put ("timestamp" , this .timestamp );
222+ map .put ("expiration" , this .expiration );
223+ map .put ("type" , this .type );
224+ map .put ("amount" , this .amount );
225+ map .put ("fee" , this .fee );
226+ map .put ("recipientId" , this .recipientId );
227+ map .put ("signature" , this .signature );
228+ map .put ("senderPublicKey" , this .senderPublicKey );
229+
230+ if (this .vendorField != null && !this .vendorField .isEmpty ()) {
231+ map .put ("vendorField" , this .vendorField );
232+ }
233+
234+ if (this .signSignature != null && !this .signSignature .isEmpty ()) {
235+ map .put ("signSignature" , this .signSignature );
236+ }
237+
238+ HashMap <String , Object > asset = new HashMap ();
239+ if (this .type == Types .SECOND_SIGNATURE_REGISTRATION ) {
240+ HashMap <String , String > publicKey = new HashMap ();
241+ publicKey .put ("publicKey" , this .asset .signature .publicKey );
242+ asset .put ("signature" , publicKey );
243+ } else if (this .type == Types .VOTE ) {
244+ asset .put ("votes" , this .asset .votes );
245+ } else if (this .type == Types .DELEGATE_REGISTRATION ) {
246+ HashMap <String , String > delegate = new HashMap ();
247+ delegate .put ("username" , this .asset .delegate .username );
248+ asset .put ("delegate" , delegate );
249+ } else if (this .type == Types .MULTI_SIGNATURE_REGISTRATION ) {
250+ HashMap <String , Object > multisignature = new HashMap ();
251+ multisignature .put ("min" , this .asset .multisignature .min );
252+ multisignature .put ("lifetime" , this .asset .multisignature .lifetime );
253+ multisignature .put ("keysgroup" , this .asset .multisignature .keysgroup );
254+ asset .put ("multisignature" , multisignature );
255+ }
256+
257+ if (!asset .isEmpty ()) {
258+ map .put ("asset" , asset );
259+ }
260+
215261 GsonBuilder gsonBuilder = new GsonBuilder ();
216- gsonBuilder .registerTypeAdapter (Types .class , new TransactionTypeDeserializer ());
217- gsonBuilder .registerTypeAdapter (Types .class , new TransactionTypeSerializer ());
218- return gsonBuilder .create ().toJson (this );
262+ return gsonBuilder .create ().toJson (map );
219263 }
220264
221265 private static class TransactionTypeDeserializer implements
0 commit comments