Forum Discussion

Ganeshu108's avatar
Ganeshu108
New Contributor II
3 years ago
Solved

Error:class java.util.ArrayList cannot be cast to class java.sql.Array

Hello ,
I am facing following issue while inserting data into postgres database from json file.

Error : class java.util.ArrayList cannot be cast to class java.sql.Array (java.util.ArrayList is in module java.base of loader ‘bootstrap’; java.sql.Array is in module java.sql of loader ‘platform’).

  • vgautam64 - I believe this solves your question in the simplest way I can think of.  Use a Mapper snap with the following configuration:

    It appears to me that you only need the field elements and values from the first group element: $group[0]

    The two jsonPath statements are simply pulling all values for the Debit and Credit Amounts into an array of numbers

    Finally, the Array.reduce() method is used to aggregate that list of numbers into a final total.

    Hope this helps!

     

3 Replies

  • jaybodra's avatar
    jaybodra
    New Contributor III

    Hi Jack,

    the best work around to this use json.loads and json.dumps; json.loads(in_doc.get(‘str_json’)). use a mapper with JSON.stringify() to represent JSON as string and then you can use json.loads() in the script.

  • Have you ever found a good solution to this besides converting it to a string prior?

    Generally, the proposed method by @jaybodra works, but it seems more like a short-term workaround.
    Additionally, I’m unable to retain the sorting of the dumps after re-loading it, even when telling it to do so specifically. So this only leaves the option of entering a string and passing out a string and then using JSON.parse(), then it will actually be an ordered json … 😮

    json_input = json.loads(inDoc.get('content'))
    json_string = json.dumps(json_input, sort_keys=True)
    json_output = json.loads(json_string, object_pairs_hook=OrderedDict)
    

    Best regards
    Thomas