While Advanced REST Client successfully retrieves an infinite JSON file from the AngularJS REST service, Postman encounters an error with the code ERR_INCOMPLETE_CHUNKED_ENCODING

I've encountered a peculiar issue. When making a REST call in Angular (using an app built with Ionic v1) to a Java endpoint, something goes awry and Chrome throws the following error: https://i.sstatic.net/1sxp7.png

The code of interest is this AngularJS REST service:

bankaccountsbyuser: function(_getbauser, _error){
            var currentToken = _GetToken();
  
            if(currentToken!=null){
                var Headers = {
                    token: currentToken.tokenUser,
                };
            }
            
            _timerTokenControl(currentToken, _error);
            
            if (setupTime == null) {
                console.log("token scaduto");
                //$window.location.href="login.html";
            }
            


            if (currentToken !== null) {
            $http({  
                        method : 'GET',  
                        headers: Headers,
                        url : REST_URL+'bankaccount'
                    }).then(function successCallback(response) {  
                        console.log(response)
                        _getbauser(response)
                    }, function errorCallback(response) {  
                        console.log(response.statusText);  
                    });  
               }  else {
                   var alertPopup = $ionicPopup.alert({
                         title: 'Accesso negato!',
                         template: 'Devi essere un utente registrato, non sei loggato!'
                     });
                    console.log("NON SEI LOGGATO!!!");
            }
        },

debug: https://i.sstatic.net/u7LYM.png

The GET REST service returns an error as shown above, let's examine the corresponding Java REST service:

package it.jack.fdd.services;

import java.util.List;
...rest of content...
return balist;

}

To simplify testing, I passed the number "1" into the method which is implemented below:

package it.jack.fdd.dao.impl;

import java.util.List;
...rest of content...
    @Override
    public List<BankAccount> getBAByUserId(int id) {

try{

Session session = HibernateUtilLezione.openSession();
Transaction tx = session.beginTransaction();

@SuppressWarnings("unchecked")
List<BankAccount> accounts = session.createQuery("from BankAccount b "
+ "where b.user= "+id).list();

tx.commit();
session.close();

return accounts;
}
catch(HibernateException e){
e.printStackTrace();
return null;
}
}

}

Upon executing the method in Java with ID 1, it returns a single record as expected.

[it.jack.fdd.domain.BankAccount@4f8d86e4]

However, when accessing this REST call in Postman, the result is different:

https://i.sstatic.net/obExc.png

Mysteriously, Postman displays the same outcome for another previously functional REST call, though this isn't an issue within the application itself but only in Postman. On the contrary, using Advanced REST Client yields a bizarrely repetitive list, almost like a loop. Any ideas on what might be causing this and how to resolve it?

Answer ā„–1

Resolved! The issue was found in the domain classes of Java: it is necessary to include the @JsonIgnore tag when a domain class has a one-to-many relationship in order to prevent repetitive records in the JSON file.https://i.sstatic.net/YFCtG.png

Here is an example of an entity class:

package it.jack.fdd.domain;
// Generated on November 30, 2016 at 0:17:09 by Hibernate Tools 4.3.1.Final

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * BankAccount generated by hbm2java
 */
@Entity
@Table(name = "bank_account", catalog = "fdd_dbproducts")
public class BankAccount implements java.io.Serializable {

private Integer idbankAccount;
private User user;
private String iban;
private String pin;
private String society;
private Date expiration;

public BankAccount() {
}

public BankAccount(User user, String iban, String pin, String society) {
this.user = user;
this.iban = iban;
this.pin = pin;
this.society = society;
}

public BankAccount(User user, String iban, String pin, String society, Date expiration) {
this.user = user;
this.iban = iban;
this.pin = pin;
this.society = society;
this.expiration = expiration;
}

@Id
@GeneratedValue(strategy = IDENTITY)

@Column(name = "idbank_account", unique = true, nullable = false)
public Integer getIdbankAccount() {
return this.idbankAccount;
}

public void setIdbankAccount(Integer idbankAccount) {
this.idbankAccount = idbankAccount;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "fkuser_baccount", nullable = false)
public User getUser() {
return this.user;
}

public void setUser(User user) {
this.user = user;
}

@Column(name = "iban", nullable = false, length = 45)
public String getIban() {
return this.iban;
}

public void setIban(String iban) {
this.iban = iban;
}

@Column(name = "pin", nullable = false, length = 45)
public String getPin() {
return this.pin;
}

public void setPin(String pin) {
this.pin = pin;
}

@Column(name = "society", nullable = false, length = 45)
public String getSociety() {
return this.society;
}

public void setSociety(String society) {
this.society = society;
}

@Temporal(TemporalType.DATE)
@Column(name = "expiration", length = 10)
public Date getExpiration() {
return this.expiration;
}

public void setExpiration(Date expiration) {
this.expiration = expiration;
}

}

Answer ā„–2

To handle both onetomany and manytomany relationships, make sure to include the @JsonIgnore annotation in the model class.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display the following line retrieved from SQLite

The Issue I'm Facing: Currently, I am encountering an issue in my application where I retrieve address information from a SQLite database and attempt to display it in a textview. An Example of Address from SQLite: - 41 South Station Road,'&bsol ...

What is the best way to add a new project and make updates to an existing project within an array?

Looking to add a new project and update existing projects within an array. Here's my plan in pseudo-JSON format. How can I update Project A in MongoDB? { _id : ..., userName: milad , projets : [ { .. projectId, pName, location .... A }, ...

Implementing user authentication on a separate domain using a RESTful web service in asp.net

My goal is to connect with a web service on a separate domain for user authentication. The web service is RESTful and written in Java, exchanging data in JSON format. I attempted to establish a connection using jQuery as shown below: function Log ...

What are the steps to ensure availability validation with jQuery validation?

I need assistance with validating post availability in the database using jQuery validation functionality. I have already implemented validation using the code below, but I am unsure where to place an Ajax validation before submitting the form. $(document ...

What steps can I take to prevent my menu items from overlapping in the mobile navigation menu?

I am currently working on creating a mobile menu, but I'm facing an issue where the menu items overlap when hovered over. Instead, I want the menu items to move downwards when hovered upon to prevent the text from overlapping. Below is the HTML code ...

Having trouble with adding data from an array of objects to an HTML element using jQuery's each method

I am currently facing an issue with looping through an array of objects using $.each in jQuery and trying to append the values to an <li>. Here is the relevant jQuery code: $(".sidebar").empty().append("<div>" + "<h5>Student Info</ ...

OECD API generates an exclusive Vega-Lite visualization

I'm trying to incorporate an API directly into Vegalite for automatic chart updates. Here is the link to the API: API Link However, the format of the API data is not user-friendly. { "$schema": "https://vega.github.io/schema/vega-lit ...

Exploring related models in the MEAN stack journey

Iā€™m currently working on setting up a model association in MEAN framework where an Epic can have multiple Tasks associated with it. I typically create the Epic first and then link it to tasks when creating them. The task data model is structured as follo ...

Issue: Unable to retrieve the property "div" as the animated object is not defined

Recently, I decided to enhance my JavaScript skills by following a tutorial on creating a dating site using the react-tinder-card component. However, during implementation, I encountered an error message: Uncaught runtime errors: ERROR can't access pr ...

Encountering an error message saying "assignment to undeclared variable"

I'm attempting to incorporate a react icon picker from material-ui-icon-picker However, I keep encountering an error stating "assignment to undeclared variable showPickedIcon" edit( { attributes, className, focus, setAttributes, setFocus, setState ...

Sending form data using Ajax in codeigniter

I am encountering an error while attempting to submit a form using ajax in codeIgniter. Below is the view code that I have: <div class="form-group input-control"> <p id="error1" style="display: none; color: green"><b>Registered Succ ...

Nothing is in the Laravel array when using `$request->all()`

In the process of developing a shopping cart using Laravel. Here are the details : Routes : Route::post('/cart/add', 'CartController@store')->name('cart.store'); Route::patch('/cart/{product}', 'CartContro ...

React: Dynamic input field that removes default value as the user begins typing

Imagine a scenario where we have a text box in a React application with Formik and Material UI that accepts a price as a floating point number. By default, the field is set to 0. However, once the user manually enters a number, the default value should be ...

What is the reason for function components running in multiples of 2 when the state changes?

I need help with a React question that I can't quite figure out. I have a component where new data keeps getting added to the existing data. Initially, it makes sense for two console logs to appear due to Mount and Update. But after that, why do 4 con ...

How come my uploaded Excel Javascript add-on opens in an external browser instead of the task pane?

Note: It has come to my attention that I must save the taskpane.html file on my local drive before it opens in an external browser. This detail slipped my notice last week. I am currently developing a Javascript, or rather Typescript, API add-in for Excel ...

What is the proper way to invoke a function in the code-behind using JavaScript?

I need to invoke a function in the code behind from JavaScript Button : <button class = "btn btn-outline btn-danger dim" type = "button" onclick = "confirmDelete ()"> <i class = "fa fa-trash"> </i> ...

Unraveling numerous JSON inquiries into a single struct

My task is to decode two JSON urls with different fields for the same item and then merge them into one model object using a struct or class. I have successfully decoded one JSON url, but am struggling to incorporate the second url. Currently utilizing str ...

Order objects in a JavaScript array

Recently, I came across a list of student data fetched from an API: const Studentdata = { "StudentName1": { "active": true, "gender": "male" }, "StudentName2": { "active": false, "gender": "male" }, "S ...

Leveraging Vuex stores in a modular WebPack setup

I am currently working on a web application where each page of the site has 2 JS files: a global "bootstrap.js" file that is consistent across every page and a custom JS file specific to each page. I've run into an issue where I want these files to sh ...

Utilizing Antlr visitor code across multiple visitor classes

In my project, I have two different grammar files and visitors named Simple and Complex. These visitors are responsible for parsing JSON objects into strings. The Complex objects that I'm parsing can contain a variety of Simple objects, along with oth ...