Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap

后端 未结 12 729
长发绾君心
长发绾君心 2020-11-27 03:08

Solved: Thanks to below answer from S.Richmond. I needed to unset all stored maps of the groovy.json.internal.LazyMap type whi

12条回答
  •  -上瘾入骨i
    2020-11-27 03:52

    You can use the following function to convert LazyMap to a regular LinkedHashMap (it will keep the order of original data):

    LinkedHashMap nonLazyMap (Map lazyMap) {
        LinkedHashMap res = new LinkedHashMap()
        lazyMap.each { key, value ->
            if (value instanceof Map) {
                res.put (key, nonLazyMap(value))
            } else if (value instanceof List) {
                res.put (key, value.stream().map { it instanceof Map ? nonLazyMap(it) : it }.collect(Collectors.toList()))
            } else {
                res.put (key, value)
            }
        }
        return res
    }
    
    ... 
    
    LazyMap lazyMap = new JsonSlurper().parseText (jsonText)
    Map serializableMap = nonLazyMap(lazyMap);
    
    

    or better use a readJSON step as noticed in earlier comments:

    Map serializableMap = readJSON text: jsonText
    

提交回复
热议问题