Understanding and parsing JSON with object pointers

Is it possible to deserialize a JSON in typescript that contains references to objects already existing within it?

For instance, consider a scenario where there is a grandparent "Papa" connected to two parents "Dad" and "Mom", who have two children together. The JSON structure looks like this:

{
  "id_": 1,
  "name": "Papa",
  "parents": [
    {
      "@class": "com.doubleip.spot.mgmt.test.domain.model.Parent",
      "id_": 1,
      "name": "Dad",
      "children": [
        {
          "@class": "com.doubleip.spot.mgmt.test.domain.model.Child",
          "id_": 1,
          "name": "Bob"
        },
        {
          "@class": "com.doubleip.spot.mgmt.test.domain.model.Child",
          "id_": 2,
          "name": "Trudy"
        }
      ]
    },
    {
      "@class": "com.doubleip.spot.mgmt.test.domain.model.Parent",
      "id_": 2,
      "name": "Mom",
      "children": [
        1,
        2
      ]
    }
  ]
}

The issue arises during front-end deserialization using TypeScript, Angular, and PrimeNG components due to the JsonIdentityInfo feature utilized in Java with fasterxml library.

Answer №1

Encountering issues with front-end deserialization

To successfully deserialize data, you will likely need to write most of the code yourself or utilize additional code from your Java source.

However, there are some useful tools available for hydration. One recommendation is using hydration helpers like: https://github.com/mobxjs/serializr

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

Deciphering JSON Data on the AWS Platform

Having trouble parsing JSON data in Linux. I'm looking for a Linux command that can help me parse JSON data into a readable string. A friend suggested using underscore-cli (https://npmjs.org/package/underscore-cli). Even after installing and using i ...

Using Javascript in n8n to merge two JSON arrays into a single data structure

When working on a project, I extract JSON objects from the Zammad-API. One of the tickets retrieved is as follows: [ { "id": 53, "group_id": 2, "priority_id": 2, "state_id": 2, "organizati ...

How to Establish an Angular Global Variable

What is the process for establishing a global variable in Angular? I have established a variable within a service, entered a value in the login component, and attempted to access this variable from another component. However, I noticed that the value res ...

Creating Instances of Variables Within a Class

Currently, I am working on a project using Ionic and Angular. I have come across various ways of instantiating variables and I'm unsure about the implications of each method. Here are three scenarios that confuse me: export class someClass { myVaria ...

Organize and display a list of contacts alphabetically by the first letter of their

I have a list of contacts that I need help with. Despite searching on Stack Overflow, I couldn't find the answer. Can someone please assist? Thank you. export const rows = [ { id: 1, name: 'Snow', email: 'Jon', co ...

Is there a way to enforce a mandatory lambda argument?

I am trying to pass a lambda into a function, but I need the lambda to have only one argument. TypeScript correctly generates an error if I provide two parameters to the lambda, however it does not raise any issues if I leave out any arguments altogether ...

Utilizing IBM Cloud Functions to display API response data within Watson Assistant using node.js and JSON formatting

Utilizing IBM cloud functions, I am making calls to two Joke APIs. The initial API returns the following results: Results: { "response": { "body": { "body": [ { "_id": "5f80ccd64178 ...

Tips for utilizing the REST service through ajax(jQuery) in a Spring Boot application

Currently, I'm referencing an official Spring document regarding this particular topic It seems like there might be something missing or omitted because despite my efforts with Intellij and SpringBoot, I can't seem to get it to work. My impleme ...

What is the method for opening the image gallery in a Progressive Web App (PWA)?

I am struggling to figure out how to access the image gallery from a Progressive Web App (PWA). The PWA allows me to take pictures and upload them on a desktop, but when it comes to a mobile device, I can only access the camera to take photos. I have tried ...

There is no link between the two containers

I am facing an issue where two containers need to connect with each other. However, when attempting to fetch data from one container, I encounter an ENOTFOUND error. Surprisingly, this code functions properly on my local system but fails within the contain ...

What is the best way to verify the presence of a value in an SQL column?

I need to check if a value exists in a column. If the value already exists, I do not want to insert it into the table. However, if it does not exist, then I want to add new data. Unfortunately, my attempted solution hasn't been successful. You can fi ...

Exploring the process of looping through S3 bucket items and delivering notifications to SQS

I've successfully developed a function that retrieves messages from an SQS Dead Letter Queue (DLQ) and uploads them to an S3 bucket. Now, my goal is to create another function or method to resend these messages from the S3 bucket. Currently, I'm ...

Comparing two JSON objects in MySQL: Best practices and tips

What is the correct syntax for comparing an entire MySql json column with a json object? The usual method doesn't seem to work as expected: select count(criteria) from my_alerts where criteria = '{"industries": ["1"], "locations": ["1", "2"]}&a ...

Contrasting Dependency Injection with Exporting Class Instances

I've been diving into the world of TypeScript and working on enhancing my skills as a web developer. One project I'm currently focused on is a simple ToDo app, which you can find here: https://github.com/ludersGabriel/toDo/tree/dev/backend. My q ...

Using lodash in Node.js to inject values by key-pair

Here is the structure of my job object: {"LAB_123":{"abc":"bde"},"LAB_345":{"abc":"efg"}} The second JSON object looks like this: {"LAB_123":{"xyz":"dfe"},"LAB_345":{"PQR":"ABC"}} I want to combine these two objects into one JSON array that will look l ...

Tips for retrieving data sent through Nextjs Api routing

Here is the API file I have created : import type { NextApiRequest, NextApiResponse } from 'next/types' import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient() export default async function handler(req: NextApi ...

In Typescript, issues arise when trying to assign types with inheritance in Generics - Type mismatch detected

As I work on creating a generic parent class to handle multiple children, I have encountered a challenge. My goal is to define an abstract function in the parent class that will take in a child object and return that same class. Here's my initial atte ...

I am currently working on creating a drag select feature in React completely from scratch, but I'm facing some challenges with

Check out this code I created for drag selection: Here's the item generation code: const items = [ 1, 2, 3, ...94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, ].map((i) => ({ item: i, selected: i === 1 })); This is the actual code responsi ...

Escaping latitude and longitude coordinates using PHP

I am looking to include longitude and latitude values in a json file. However, the current code I have escapes the values and adds quotation marks. Example of json output{"votes":["{\"lat\":\"51.426799\",\"lng\":\"-0.331 ...

The number in Typescript should fall between 0 and 1, inclusive

Is there a method in Typescript that guarantees the value of a number will be less than or greater than a certain threshold? Currently, it permits the specification of a range of values, but I'm unsure about comparison. This is similar to what I have ...