views:

108

answers:

1

Please consider this code. Is it using Circular Reference? If not why am I getting CircularReferenceException, while enabling NO_REFERENCE mode in XStream. Anyone, please clarify the thing.

@XStreamAlias("BalanceEnquiry")
public class BalanceEnquiry extends EAIRequest {

    @XStreamImplicit
    private List<BalanceEnquiry.Detail> details;

    public List<Detail> getDetails() {
        ....
    }

    public void setDetails(Detail... details) {
        ....
    }

    @XStreamAlias("details")
    public final class Detail {

        @XStreamAsAttribute
        private String item;
        private BalanceEnquiry.Detail.Request request;

        public String getItem() {
            ....
        }

        public void setItem(String item) {
            ....
        }

        public Request getRequest() {
            ....
        }

        public void setRequest(Request request) {
            ....
        }

        public final class Request {

            private String code;
            private String branch;

            public String getCode() {
                ....
            }

            public void setCode(String code) {
                ....
            }

            public String getBranch() {
                ....
            }

            public void setBranch(String branch) {
                ....
            }
        }
    }
}
+1  A: 

I suspect it's because Detail is an inner class. As such, it has an implicit reference to the instance of the outer class (and hence forms a circular reference). See here for more details.

Brian Agnew
Yes, I just finished to understand this, after brushing up some basics. Thanks for the link, anyway. +1
Adeel Ansari