javatalend

Java Code to get Object Data Type in Talend using tJava or tJavaRow


I'm trying to get a data from an Object Type. Any idea how to create java code to retrieve data from it? I am getting data from a MongoDB database.

.------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.
|                                                                                                                                                                                                                                      #1. tLogRow_2                                                                                                                                                                                                                                       |
+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| key            | value                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| patient_oid    | null                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| mrn            | MRN23051413                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| registereddate | 2023-08-07 12:10:29.088                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| test           | null                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| address        | {"_id": {"$oid": "64d06eb518977e642aea2c31"}, "address": "20 ROSAL SAMPAGUITA MALANDAY", "area": "Malanday", "areauid": {"$oid": "5fe31af39034622774565a25"}, "city": "Marikina", "cityuid": {"$oid": "5f6ad6f56714265e8bbbba51"}, "state": "NCR, 2nd district", "stateuid": {"$oid": "5f6ad3716714265e8bb9b73b"}, "country": "Philippines", "countryuid": {"$oid": "5f6ad3706714265e8bb9b631"}, "zipcode": "1805", "zipcodeuid": {"$oid": "5fe306599034622774557943"}} |
+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

[statistics] disconnected

Job testmongodb ended at 16:18 15/08/2023. [Exit code  = 0]

I want to have this kind of output

patient_oid        | null
mrn                | MRN23051413           
registereddate     | 2023-08-07 12:10:29.088 
address_address    | 20 ROSAL SAMPAGUITA MALANDAY
address_area       | Malanday
address_city       | Marikina
and so on......

The application is accepting java code hopefully someone can help how they did it in java in other application

This is the auto generated code in tJavaRow which return the same object type enter image description here

Thank you in advance


Solution

  • Your field "address" seems to be a json. You should get it as a string from your first input component. Then you could parsethis string with a tExtractJsonFields component to extract data from it. Check documentation of tExtractJsonFields component to know more about it.