• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading Complex Map and Collection

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am struck in a problem please let me know if you have any idea how to proceed on this.

I have a method myMethod(Map<String, Object> inputData) this Object can be a String/PrimitiveWrapper/Map/Collection i.e List/Vector. I need to get the values from this Object in the format given below.

If the Object is a Map. If it’s a simple Map its fine but this one is a complex Map. This Map can contain any type of data.
Suppose if it contains the data as shown below:



I need to iterate the eight Map i.e in backward direction and values should be read as below. The big question is how do I know what is there in the Object. As this Object can contain any data structure.

Description of the above values:
Customers is the key of eight map that contains seven
Customer is the key of seven that contains a list six so it should be index form Customer[0], Customer[1]
fiveA is part of six at index 0,
Addresses is the key of fiveA, that contains Map four
Address is the key of four that contains a list three, so it should be index for Address[0], Address[1].
AddressLine1 is the key of one and has value House 1
so the final value from the top looks like this:

Now I need to get the values in the above way and put the same in another map.


There will be no XML data as input, only it will be of the form myMethod(Map<String, Object> inputData) and this Object can be a String/PrimitiveWrapper/Map/Collection i.e List/Vector. Now the inputData I have to process is: myMethod(Map<String, Object> eight)

Thanks in Advance
Khan

 
Ranch Hand
Posts: 87
Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch



I would probably create a Customer class and Address class and then may be use "instanceof" operator, rather than what is shown in your code.
 
Rauf Khan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pillai thanks for the reply.

But here I cant create any class, how will I know what is the input Map data. The values Customers, Customer, Addresses, .... are Map Key values. There might be something in java how to read such type of data. The one which I have shown is the sample. The same map can contain extra data also.



Output:

 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you just create a Customer class, which contains fields like name and address; then you just return a List<Customer>?
 
Rauf Khan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephan thanks for the response.

I cannot create a Customer class. Am getting the data from the third party and I need to process through that data and get the values. I get the data in the format HashMap<String, Object> only. I have no idea what is present in the Map. I just need to iterate and get the data.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you get the data? Is it sent to you through a socket connection or something? When you're done reading the data, what's going to happen to it? Are you going to process it yourself, does it get delegated to third party classes?

TellTheDetails please.
 
prem pillai
Ranch Hand
Posts: 87
Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rauf Khan wrote:I cannot create a Customer class. Am getting the data from the third party



Rauf , for integrating your system with a thirdparty system, the first thing you need is a contract defining how these two systems are going communicate each other and what should be the structure of the data.. This is true even in case you are just using just thirdparty library- there the contract may just an API exposed by the thirdparty library... Are you saying that you don't this information with you ? If so thats not a very encouraging situation ...

 
Rauf Khan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am developing a component which will be place in the application as a JAR. The application will call my method and pass input data in format (Map<String, Object> inputData)and i need to process this data.

I got the first break through to get the values but still couldnt get the output as expected. Can anyone please help me out to get the exact output.



Expected output:


Actual Output
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rauf Khan wrote:and i need to process this data


How do you know how to process this data? Where is the contract?
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic