-1

I am working on Java Object to JSON conversion using ObjectMapper but it is giving extra attribute which is not present in my java class.

Below is the Java Object Builder class.

@JsonDeserialize(builder = OrderSummary.Builder.class)
public class OrderSummary extends ABC {

    @JsonProperty("orderCode")
    private String orderCode;

    @JsonProperty("transactionAmount")
    private long transactionAmount;

    @JsonProperty("transactionCurrency")
    private String transactionCurrency;

    @JsonProperty("isPayout")
    private boolean isPayout;

    private OrderSummary(Builder builder) {
        super(builder);
        orderCode = builder.orderCode;
        transactionAmount = builder.transactionAmount;
        transactionCurrency = builder.transactionCurrency;
        isPayout = builder.isPayout;
    }
    public static Builder newBuilder() {
        return new Builder();
    }

    public String getOrderCode() {
        return orderCode;
    }
    public long getTransactionAmount() {
        return transactionAmount;
    }
    public String getTransactionCurrency() {
        return transactionCurrency;
    }
    public boolean isPayout() {
        return isPayout;
    }

    @JsonPOJOBuilder
    public static final class Builder extends ABC.Builder<Builder> {

        private String orderCode;

        private long transactionAmount;

        private String transactionCurrency;

        private boolean isPayout;

        private Builder() {
        }

        public Builder withOrderCode(String val) {
            orderCode = val;
            return this;
        }
        public Builder withTransactionAmount(long val) {
            transactionAmount = val;
            return this;
        }
        public Builder withTransactionCurrency(String val) {
            transactionCurrency = val;
            return this;
        }
        public Builder withIsPayout(boolean val) {
            isPayout = val;
            return this;
        }
        public OrderSummary build() {
            return new OrderSummary(this);
        }
        @Override
        protected Builder self() {
            return this;
        }
    }
}

It extends 1 class which has only 2 attributes

  1. transaction code
  2. unique identifier

But when I have using Object Mapper object to convert to json getting below json

{
              "payout": false,
              "transactionCode": "ABCJD",
              "uniqueIdentifier": 78632,
              "orderCode": "12345",
              "transactionAmount": 1200,
              "transactionCurrency": "EUR",
              "isPayout": false,
}

I am not sure how "payout": false, is added in json.

I tried converting another java object which does not have boolean it is working fine without any issue.

Can you please help me in how can I fix this conversion.

1

1 Answer 1

0

I don't know what is the whole process that you are did, and how BUT.

some solution that could be

  1. adding this annotation to serialized class

    @JsonIgnoreProperties({"payout"})

  2. use google gson, it very efficient, very secure and very good serializer in all software engineering terms.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.