Implementing the UserAccount#toJsonString method
This commit is contained in:
parent
519a1a4dd8
commit
7b9b694a71
2 changed files with 97 additions and 10 deletions
|
@ -1,11 +1,14 @@
|
|||
package de.bitsharesmunich.graphenej;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutput;
|
||||
|
@ -20,8 +23,7 @@ import de.bitsharesmunich.graphenej.interfaces.ByteSerializable;
|
|||
import de.bitsharesmunich.graphenej.interfaces.JsonSerializable;
|
||||
|
||||
/**
|
||||
* Class tha represents a graphene user account.
|
||||
* Created by nelson on 11/8/16.
|
||||
* Class that represents a graphene user account.
|
||||
*/
|
||||
public class UserAccount extends GrapheneObject implements ByteSerializable, JsonSerializable {
|
||||
|
||||
|
@ -46,19 +48,43 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso
|
|||
public static final String KEY_ACTIVE_SPECIAL_AUTHORITY = "active_special_authority";
|
||||
public static final String KEY_N_CONTROL_FLAGS = "top_n_control_flags";
|
||||
|
||||
private long membershipExpirationDate;
|
||||
private String registrar;
|
||||
private String referrer;
|
||||
private String lifetimeReferrer;
|
||||
private long networkFeePercentage;
|
||||
private long lifetimeReferrerFeePercentage;
|
||||
private long referrerRewardsPercentage;
|
||||
@Expose
|
||||
private String name;
|
||||
|
||||
@Expose
|
||||
private Authority owner;
|
||||
|
||||
@Expose
|
||||
private Authority active;
|
||||
|
||||
@Expose
|
||||
private AccountOptions options;
|
||||
|
||||
@Expose
|
||||
private String statistics;
|
||||
|
||||
@Expose
|
||||
private long membershipExpirationDate;
|
||||
|
||||
@Expose
|
||||
private String registrar;
|
||||
|
||||
@Expose
|
||||
private String referrer;
|
||||
|
||||
@Expose
|
||||
private String lifetimeReferrer;
|
||||
|
||||
@Expose
|
||||
private long networkFeePercentage;
|
||||
|
||||
@Expose
|
||||
private long lifetimeReferrerFeePercentage;
|
||||
|
||||
@Expose
|
||||
private long referrerRewardsPercentage;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor that expects a user account in the string representation.
|
||||
|
@ -120,7 +146,8 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso
|
|||
|
||||
@Override
|
||||
public String toJsonString() {
|
||||
return this.getObjectId();
|
||||
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
return gson.toJson(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package de.bitsharesmunich.graphenej;
|
||||
|
||||
import com.neovisionaries.ws.client.WebSocketException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.bitsharesmunich.graphenej.api.BaseApiTest;
|
||||
import de.bitsharesmunich.graphenej.api.GetObjects;
|
||||
import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
|
||||
import de.bitsharesmunich.graphenej.models.BaseResponse;
|
||||
import de.bitsharesmunich.graphenej.models.WitnessResponse;
|
||||
|
||||
/**
|
||||
* Created by nelson on 5/20/17.
|
||||
*/
|
||||
public class UserAccountTest extends BaseApiTest {
|
||||
private final UserAccount bilthon_25 = new UserAccount("1.2.151069");
|
||||
|
||||
@Test
|
||||
public void testToJsonString() {
|
||||
try{
|
||||
ArrayList<String> ids = new ArrayList<>();
|
||||
ids.add(bilthon_25.getObjectId());
|
||||
mWebSocket.addListener(new GetObjects(ids, new WitnessResponseListener() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(WitnessResponse response) {
|
||||
System.out.println("onSuccess");
|
||||
List<GrapheneObject> result = (List<GrapheneObject>) response.result;
|
||||
UserAccount userAccount = (UserAccount) result.get(0);
|
||||
System.out.println("user account: "+userAccount.toJsonString());
|
||||
|
||||
synchronized (UserAccountTest.this){
|
||||
UserAccountTest.this.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(BaseResponse.Error error) {
|
||||
System.out.println("onError");
|
||||
synchronized (UserAccountTest.this){
|
||||
UserAccountTest.this.notifyAll();
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
mWebSocket.connect();
|
||||
synchronized (this){
|
||||
wait();
|
||||
}
|
||||
}catch (WebSocketException e) {
|
||||
System.out.println("WebSocketException. Msg: " + e.getMessage());
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("InterruptedException. Msg: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue