Skip to content

Commit

Permalink
Adding public empty constructors for JSON parsing and Response Data R…
Browse files Browse the repository at this point in the history
…esolver.

Signed-off-by: Dima Rudenko <dima@coti.io>
  • Loading branch information
dimaru-coti committed Apr 16, 2023
1 parent 09b402a commit 73c3f9a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ <T extends BaseTransactionResponseData> BaseTransactionResponseClass(Class<T> re
public Class<? extends BaseTransactionResponseData> getResponseClass() {
return responseClass;
}

public static BaseTransactionResponseClass getName(Class<?> baseTransactionClass) {
for (BaseTransactionResponseClass name : values()) {
if (name.getResponseClass() == baseTransactionClass) {
return name;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.coti.basenode.http.data;


import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver;
import io.coti.basenode.data.BaseTransactionData;
import io.coti.basenode.data.BaseTransactionName;
import io.coti.basenode.http.data.interfaces.IResponseData;
Expand All @@ -10,6 +12,8 @@
import java.time.Instant;

@Data
@JsonTypeInfo(use = JsonTypeInfo.Id.CUSTOM, property = "name")
@JsonTypeIdResolver(BaseTransactionResponseDataResolver.class)
public abstract class BaseTransactionResponseData implements IResponseData {

private String hash;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.coti.basenode.http.data;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.DatabindContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.jsontype.impl.TypeIdResolverBase;

public class BaseTransactionResponseDataResolver extends TypeIdResolverBase {

@Override
public String idFromValue(Object value) {
return idFromValueAndType(value, value.getClass());
}

@Override
public String idFromValueAndType(Object value, Class<?> suggestedType) {
BaseTransactionResponseClass baseTransactionResponseClass = BaseTransactionResponseClass.getName(suggestedType);
if (baseTransactionResponseClass == null) {
throw new IllegalStateException("Invalid base transaction class " + suggestedType);
}
return baseTransactionResponseClass.name();
}

@Override
public JsonTypeInfo.Id getMechanism() {
return JsonTypeInfo.Id.CUSTOM;
}

@Override
public JavaType typeFromId(DatabindContext context, String id) {
try {
BaseTransactionResponseClass baseTransactionResponse = BaseTransactionResponseClass.valueOf(id);
return context.constructType(baseTransactionResponse.getResponseClass());
} catch (IllegalArgumentException e) {
throw new IllegalStateException("Invalid base transaction name " + id, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
@EqualsAndHashCode(callSuper = true)
public class FullNodeFeeResponseData extends OutputBaseTransactionResponseData {

public FullNodeFeeResponseData() {
super();
}

public FullNodeFeeResponseData(BaseTransactionData baseTransactionData) {
super(baseTransactionData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class NetworkFeeResponseData extends OutputBaseTransactionResponseData {
private BigDecimal reducedAmount;
private List<TrustScoreNodeResultResponseData> networkFeeTrustScoreNodeResult;

public NetworkFeeResponseData() {
super();
}

public NetworkFeeResponseData(BaseTransactionData baseTransactionData) {
super(baseTransactionData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class ReceiverBaseTransactionResponseData extends OutputBaseTransactionRe

private String receiverDescription;

public ReceiverBaseTransactionResponseData() {
super();
}

public ReceiverBaseTransactionResponseData(BaseTransactionData baseTransactionData) {
super(baseTransactionData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class RollingReserveResponseData extends OutputBaseTransactionResponseDat
private BigDecimal reducedAmount;
private List<TrustScoreNodeResultResponseData> rollingReserveTrustScoreNodeResult;

public RollingReserveResponseData() {
super();
}

public RollingReserveResponseData(BaseTransactionData baseTransactionData) {
super(baseTransactionData);

Expand Down

0 comments on commit 73c3f9a

Please sign in to comment.