Incorrect naming in JSON response from REST API service

Currently, I am in the process of developing a web application using AngularJS and TypeScript with a Netbeans RESTful backend. I have created a TypeScript interface for a vendor which looks like this:

interface Vendor {
    vendorno: number,
    name: string,
    address1: string,
    city: string,
    province: string,
    postalcode: string,
    phone: string,
    vendortype: string,
    email: string;
}

However, when I retrieve all vendor data from my JavaDB through the REST service, the JSON returned has properties named differently than what is defined in my interface. This causes issues with my angular directives as I need to refer to the JSON naming scheme instead:

[{"vendorAddress":"543 Sycamore Ave","vendorCity":"Toronto","vendorEmail":"emailplaceholder","vendorName":"Big Bills Depot","vendorNo":1,"vendorPhone":"(999) 555-5555","vendorPostalcode":"N1P1N5","vendorProvince":"ON","vendorType":"Trusted"},
{"vendorAddress":"628 Richmond Street","vendorCity":"London","vendorEmail":"emailplaceholder","vendorName":"ABC Supply Co.","vendorNo":2,"vendorPhone":"(519) 123-4567","vendorPostalcode":"N6C1L7","vendorProvince":"ON","vendorType":"Trusted"},
{"vendorAddress":"123 Main Boulevard","vendorCity":"Burlington","vendorEmail":"emailplaceholder","vendorName":"Gadget Shack","vendorNo":3,"vendorPhone":"(613) 444-3423","vendorPostalcode":"N3X5S2","vendorProvince":"ON","vendorType":"Unknown"}]

To display this vendor information in a table within my partial, I must use the following angular bindings:

<div class="col-lg-1 col-sm-1 col-xs-1 text-left">{{vend.vendorNo}}</div>
<div class="col-lg-4 col-sm-4 col-xs-4 text-center">{{vend.vendorName}}</div>
<div class="col-lg-3 col-sm-3 col-xs-3 text-center">{{vend.vendorCity}}</div>
<div class="col-lg-3 col-sm-3 col-xs-3 text-center">{{vend.vendorType}}</div>

I'm wondering why either AngularJS or my Java REST service is automatically renaming the returned JSON property names?

Answer №1

Could there be a specific reason why my JSON property names are being automatically changed by either angularJS or my Java REST service?

It seems more likely that the Java REST service is responsible for this, not angular.

One potential solution would be to modify the interface in order to align it with the server response :

interface Vendor {
    vendorNo: number;
    vendorName: string;
    // and so forth ...
}

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

Is it possible to focus on particular sub-schemas in Mongoose and MongoDB?

My mongoose schema looks like this: const textSchema = new Schema({ title: { type:String, unique: true }, sentences: [SentenceSchema], }) Imagine a typical text with around 100 sentences. If I make a slight change to one sentence on the front-end, ho ...

Limitation on calling $http.get() multiple times is in place

Complete Rewriting Of Inquiry The situation has taken a new turn, prompting me to clarify the current scenario from scratch. My goal is to develop a straightforward message board using Node, Express, MongoDB, and Angular. On the server side, my get and ...

FETCH user details quickly

Greetings! My goal is to implement a feature where a user can be passed into a GET request to view the items they have posted. Below is the structure of the GET request: // @route GET with NAME // @desc GET All ITEMS WITH NAME // @access private route ...

Encountering an "emit" error while working with PouchDB in Angular 2

Within my Ionic2 application, I have created a provider to inject PouchDB design documents. However, I encountered this TypeScript error: Typescript Error Cannot find name 'emit'. src/providers/design-docs.ts if (user.location) { emit(user ...

Ignore the property if unable to parse it when using JavaScriptSerializer.Deserialize()

When deserializing JSON strings into Person objects, I use the following code snippet: JavaScriptSerializer serializer = new JavaScriptSerializer(); Person person = serializer.Deserialize<Person>(jsonString); The Person class includes an Age proper ...

Instructions for transforming rows into columns in JSON format

Looking to convert an array of JSON objects into a format where rows become columns and the values at the side become column values, similar to the crosstab function in PostgreSQL. The JSON data looks something like this: {"marketcode":"01","size":"8,5", ...

Looking to construct dynamic checkboxes in Angular by parsing a JSON object retrieved through AJAX

I have a JSON document structured like the example below, and I am looking to generate checkboxes dynamically using Angular. let data = { "Name":[ { "tagId":4489,"name":"Name","label":"Employee Name" } ], "Service":[ { "tagId": ...

A guide to navigating through arrays and retrieving key values in PHP

I need help with iterating over an array that contains a decoded JSON string. My goal is to create separate variables for first name, last name, etc., and then display them in individual rows within a table. Below is an example of the array structure. Si ...

Can you provide guidance on utilizing wildcard characters to search within a nested JSON structure?

Is there a way to utilize bigquery search() function on a nested json while incorporating a wildcard in the string literal? Take a look at the example provided below, paying attention to the % wildcard used at the end of the search string. It would be ben ...

Obtain the ViewContainerRef object from the Component

Looking to create nested components in Angular 4? This is the Chooser Component import {InputComponent} from './input/input.component' import {BlockComponent} from './block/block.component' export const FormChooser = { Block: Block ...

The EmailInstructorsComponent is missing a component factory. Make sure you have added it to @NgModule.entryComponents

I am currently utilizing the ngx-admin template and attempting to create a modal that will open upon clicking a button. My goal is to display a form within the modal window, however, upon clicking the button, the modal opens but the form does not appear, r ...

Utilizing FileInterceptor with a websocket in NestJs: A Step-by-Step Guide

Is it possible to implement this on a websocket, and if so, how can I achieve that? @UtilizeInterceptors( DocumentInterceptor('image', { location: '../data/profileImages', restrictions: { size: byte * 10 }, ...

Angular's DecimalPipe will truncate any strings that exceed 10 digits

Using the decimal pipe to format numbers in an input field value| number:'0.0-6': 'en-us' When working with numbers containing more than 10 digits, it displays as follows: For 11111111111.123456, it formats to 11,111,111,111.123455 ...

The server mistakenly interprets an Android HTTP POST request as a GET request despite being sent correctly from the application

I am currently working on a university project where I need to send some information to a server. The issue I am facing is that the server only accepts POST requests and does not parse GET requests. Even though I am sending an httpPost request using a bui ...

Retrieving information from an API on the front end without exposing the API key

Currently, I'm working on creating a page that showcases data fetched from an API. While most of the data is updated every 4 hours on the server side, some only get updated when a client requests the index route. This results in a delay as the data ne ...

What is the process for importing a node module into an Angular web worker?

When attempting to import a node module within an Angular 8 web worker, I encounter a compile error stating 'Cannot find module'. Does anyone have a solution for this issue? I created a new worker within my electron project using ng generate web ...

Issue encountered when utilizing ngResource in factory: unable to choose JSON index

ngResource in a factory is functioning properly, but unfortunately, it is only able to select the index of the JSON. However, it is also possible to bind the same variable $scope.resultItems. The console log appears as follows ...

Is there a way to eliminate the right margin in React?

I am currently working with React to layout three elements below the topElement. My goal is to have these 3 elements fill up the space equally beneath topElement, removing the right-hand gap highlighted in red in the provided image (while keeping the gap a ...

Can you explain the purpose of the MomentInput type in ReactJS when using TypeScript?

I am currently facing an issue where I need to distinguish between a moment date input (material-ui-pickers) and a normal text input for an event in my project. const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => { const i ...

`Is there a way to effectively test an @Input component in Angular?`

Despite multiple successful attempts in the past, I am facing some difficulty getting this to function properly. Within my component, I have an input @Input data: Data, which is used in my template to conditionally display certain content. Oddly enough, du ...