Unlocking the secrets of accessing HashMaps containing Objects post conversion to JSON

In my Java code, I have created a data structure using HashMap that stores PriceBreak objects along with corresponding PricingElement ArrayLists. This data has been sent to the client via GSON. However, when I try to access this object in JavaScript and log it to the console, the output is quite complex.

Object {
         PriceBreak [amount=50-99, discountedPrice=n/a] orderNo:0 forDeletion: false forChanging: false forAdding: false: Array[5],
         PriceBreak [amount=250+, discountedPrice=n/a] orderNo:0 forDeletion: false forChanging: false forAdding: false: Array[5], 
         PriceBreak [amount=1-9, discountedPrice=n/a] orderNo:0 forDeletion: false forChanging: false forAdding: false: Array[5], 
         PriceBreak [amount=100-249, discountedPrice=n/a] orderNo:0 forDeletion: false forChanging: false forAdding: false: Array[5], …
}

I am struggling to figure out how to access the individual key members or values. It seems like all keys are named PriceBreak and I am unsure how to target a specific one. Do you have any suggestions on how to tackle this issue?

Answer №1

Java Programming

HashMap<PriceBreak, ArrayList<PricingElement>> dataMap;
...
Set<PriceBreak> keySet = dataMap.keySet(); 
Collection<ArrayList<PricingElement>> values = dataMap.values();

Javascript:

// retrieve keys
var keyArray = [];
for(var k in dataMap) keyArray.push(k.key);

//retrieve a value:
value = dataMap[someKey];

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

Issues with monitoring multi-touch gesture events using Hammer JS

Can anyone figure out why this code, which utilizes hammer.js for multi-touch gesture events, is not functioning as expected? This code closely resembles one of the examples on Hammer's documentation. Despite setting up swipe events on specific elem ...

JQuery allows for multiple drag and drop functionalities, including events that occur after an object

I'm currently working on a .php page where I need to implement a drag-and-drop functionality. There will be 3 draggable elements that must be placed in their corresponding droppable elements - each draggable can only be dropped in a specific droppable ...

Configuring Firefox settings in Nightwatch

Is there a way to set Firefox preferences in nightwatch? I am trying to achieve the same thing in Java using nightwatch. To set Firefox preferences in nightwatch, you can use the following code snippet: FirefoxProfile profile = new FirefoxProfile(); prof ...

AJAX Image Upload: How to Transfer File Name to Server?

Has anyone successfully uploaded an image to a web server using AJAX, but struggled with passing the file name and path to the PHP script on the server side? Here is the HTML code along with the JavaScript (ImageUpload01.php) that triggers the PHP: Pleas ...

Processing a JSON array of objects in AngularJS

When using Angular's fromJson function to parse a JSON string, I encountered an issue. If the JSON is a simple array like "[1, 2]", the code works fine. However, I need to work with an array of dictionaries instead. var str = "[{'title' ...

Can you explain the inner workings of List.size() and how it functions when the list is implemented

Could you go into detail about the internal workings of list.size() considering that List is an interface? Where can I find the implementation for this method? ...

Guidelines for implementing drag and drop functionality for my specific scenario

Looking to create a restricted area for dragging elements within my app. Specifically, I want the element to only be draggable within a certain defined space. Here is what I currently have: http://jsfiddle.net/L73T5/10/ html <div id='background ...

Is there an issue with the parametrized function?

Below is the method signature for running scheduled tasks: private <E extends Enum<E>, T extends Task<E>> void runJob(T task, Map<Enum<E>, Job> taskTypeJobMap, ...

React useEffect not working when using the default state

I'm currently facing an issue where setting the page to its default value from the refresh function does not trigger the useEffect hook on the first attempt. However, if I run the refresh function for the second time, it works fine. Interestingly, thi ...

The repairDatabase function cannot be found in the Collection.rawDatabase() method

Seeking guidance on repairing a database within Meteor. Currently executing the following code: Meteor.methods({ 'repairDB'(){ Users.rawDatabase().repairDatabase(); return true; } }); Encountering the following error: I20170630-18: ...

Working with json, lists, and dictionaries in Python

Apologies for the extensive content, but I wanted to provide all necessary details. I am in the process of extracting specific data points from a JSON file with the following structure: { "count": 394, "status": "ok", "data": [ { ...

Bing Maps API: The function directionsManager.getAllWaypoints() does not provide latitude and longitude information

I am currently utilizing the Bing map AJAX control in my code, which looks something like this - function getMap() { map = new Microsoft.Maps.Map(document.getElementById('mnMap'), { credentials: 'MyKey', mapTypeId: Microsof ...

Issues with Ajax calls not functioning properly within CakePHP

I'm attempting to make an AJAX request in CakePHP. The submit button is marked as #enviar and the action as pages/contato. This is the code for my AJAX request: $(document).ready(function() { $('#enviar').click(function(){ $. ...

Transmit information using jQuery to an MVC controller

I am developing an ASP.NET MVC3 application and need to send three pieces of data to a specific action when the user clicks on an anchor tag: <a onclick='sendData(<#= Data1,Data2,Data3 #>)'></a> Here is the javascript function ...

Using localStorage in the client side of nextJS is a breeze

Encountering an error while attempting to retrieve local storage data. Even with the use client directive in place at the beginning, the issue persists. 'use client'; const baseURL = 'https://localhost:7264'; const accessToken = localSt ...

Is there a way for me to record the variable's name instead of its linked data?

Currently, I am developing a node.js program that monitors the prices of different currencies. While I can successfully retrieve the prices, I would like the program to also display the names of the currencies along with their prices. In the code snippet b ...

What could be causing the slow loading time of my Shopify App developed using Next.js (React)?

I recently followed a tutorial at However, I am facing severe performance issues with my app. It loads extremely slowly when changing tabs, whether it's running on ngrok, localhost, or deployed on app engine. I'm new to React, Next.js, and Shop ...

Guide on incorporating text input areas into specific positions within a string

Looking for a way to replace specific words in a string with input fields to enter actual values? For example... Dear Mr. [Father_name], your son/daughter [name] did not attend class today. This is what I want it to look like... Dear Mr. Shankar, your ...

Creating a series of spots arranged in a semi-transparent line using JavaScript for a unique canvas

My attempt at creating a highlighter is encountering issues with transparency The problem might be due to using lineCap=round, resulting in multiple dark spots appearing in a single line (which shouldn't happen). It's difficult to fully describe ...

Is it possible to create a standard response template that includes fields for value, error, and warning messages?

The official documentation sample states that responses from OneNote may have the following structure: { value:{the content we requested}, error:{error if exists with warnings inside if exist}, @api.diagnostics:{warnings if exist} } However, if the ...