Skip to content

deploy object to json order issue #155

@seongwookim9823

Description

@seongwookim9823

NamedArg is not in the correct order when converting deploy object to json through object mapper.
Example code and return value

val json =  CasperObjectMapper().writeValueAsString(deploy)
out json=

"session": {
      "Transfer": {
        "args": [
          [
            {
              "bytes": "0400f90295",
              "cl_type": "U512"
            },
               "amount"
          ],
          [
            {
              "bytes": "015123adc4338656e50c89681fa5cf0a83cd7db3a22895c072de99bfeba304b6ec",
              "cl_type": "PublicKey"
            },
            "target"
          ],
          [
            {
              "bytes": "010100000000000000",
              "cl_type": {
                "Option": "U64"
              }
            },
            "id"
          ]
        ]
      }
    },

Could you add @JsonPropertyOrder to solve the above problem?

@JsonPropertyOrder({"type", "clValue"})
public class NamedArg<P extends AbstractCLType> implements CasperSerializableObject {
    private String type;
    private AbstractCLValue<?, P> clValue;

    public void serialize(SerializerBuffer ser, Target target) throws ValueSerializationException, NoSuchTypeException {
        ser.writeString(this.type);
        this.clValue.serialize(ser, target);
    }

    public static <P extends AbstractCLType> NamedArg.NamedArgBuilder<P> builder() {
        return new NamedArg.NamedArgBuilder();
    }

    public String getType() {
        return this.type;
    }

    public AbstractCLValue<?, P> getClValue() {
        return this.clValue;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setClValue(AbstractCLValue<?, P> clValue) {
        this.clValue = clValue;
    }

    public NamedArg() {
    }

    public NamedArg(String type, AbstractCLValue<?, P> clValue) {
        this.type = type;
        this.clValue = clValue;
    }

    public static class NamedArgBuilder<P extends AbstractCLType> {
        private String type;
        private AbstractCLValue<?, P> clValue;

        NamedArgBuilder() {
        }

        public NamedArg.NamedArgBuilder<P> type(String type) {
            this.type = type;
            return this;
        }

        public NamedArg.NamedArgBuilder<P> clValue(AbstractCLValue<?, P> clValue) {
            this.clValue = clValue;
            return this;
        }

        public NamedArg<P> build() {
            return new NamedArg(this.type, this.clValue);
        }

        public String toString() {
            return "NamedArg.NamedArgBuilder(type=" + this.type + ", clValue=" + this.clValue + ")";
        }
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions