Circular reference in JSON call bring id and ref thus undefined values to the option list

52 views Asked by At

I have an optionlist that is bringing undefined values in dropdown along with few values. In response data only few values are coming with ID rest are REF(undefined). The entity it's linked to has a column ID and another column which is self join to ID named parent_set. Below code shows entity:-

@JsonDeserialize
@JsonIdentityInfo(generator = JSOGGenerator.class)
@EqualsAndHashCode(of = {"id"})
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"}, ignoreUnknown = true)
@Entity
public class QSet implements Identifiable {

@Getter
@Setter
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "id", length = 32)
private String id;

@Getter
@Setter
@Column(name = "name")
private String name;

@Getter
@Setter
@ManyToOne(optional = false, fetch = FetchType.EAGER)
@JoinColumn(name = "parent_set")
private QuestionSet parentSet;
}

HTML:-

<select ng-model="newstage.questionSet" id="questionSet" name="questionSet"
       data-toggle="tooltip" class="form-control" ng-options="set.id as set.displayText for set in qSets"/>

JS:-

$scope.qSets = response.data;

On debugging response data is :-

0: {@id: "1", id: "8a", name: "Test", parentSet: {…},  …}
1: {@ref: "113"}
2: {@id: "343", id: "8a81813a69fd55a5016a25c5ab9e0468", name: "test3", parentSet: null,  …}

In this case the value is coming as undefined for the second item in the list because it is referenced in parentset of id 1. How can I resolve this issue?

1

There are 1 answers

0
MadMax On

Well the fix was to decode the response data as below:

 $scope.qSet = JSOG.decode(response.data);