0

Why does it work fine locally, and when uploading to the server, the groovy.util.slurpersupport.Attributes cannot be cast to java.util.Map error occurs? How do I fix it?

import groovy.json.JsonSlurper
import groovy.sql.Sql

import java.sql.Connection
import java.sql.DriverManager



class WORK_XML {

    def execute(Connection conn, InputStream P_FILE) {

        Sql sql = new Sql(conn)

        def person = new XmlSlurper().parse(P_FILE)
        
        def ab = person.Doc.@Ver


    }

    static void main(String... args) {
        Class.forName("oracle.jdbc.driver.OracleDriver")
        Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@10.99.22.31:1755/ORC2", "TEST", "TEST")
        connection.setAutoCommit(true)

        try {

            def P_FILE = new File("C:\\test.xml").newInputStream()

            def SSC = new WORK_XML()
            def res = SSC.execute(connection, P_FILE)

        } finally {
            connection.close()
        }
    }

}
Ekz0
  • 63
  • 1
  • 8
  • What is the difference between your local installation and your server? – cfrick Apr 14 '21 at 19:59
  • Can you show the stacktrace that leads to the casting exception? – Jeff Scott Brown Apr 15 '21 at 13:35
  • Is that the full code or are you doing something with the `res` or `ab` variables that is not shown here? The `@Ver` expression returns a `groovy.xml.slurpersupport.Attributes` object and if you are trying to return it from a method with `Map` return type or otherwise coerce that value to a `Map` then you would get this error. – Matias Bjarland Apr 16 '21 at 08:50

0 Answers0