Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap

后端 未结 12 751
长发绾君心
长发绾君心 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条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 03:51

    The other ideas in this post were helpful, but not quite all I was looking for - so I extracted the parts that fit my need and added some of my own magix...

    def jsonSlurpLaxWithoutSerializationTroubles(String jsonText)
    {
        return new JsonSlurperClassic().parseText(
            new JsonBuilder(
                new JsonSlurper()
                    .setType(JsonParserType.LAX)
                    .parseText(jsonText)
            )
            .toString()
        )
    }
    

    Yes, as I noted in my own git commit of the code, "Wildly-ineffecient, but tiny coefficient: JSON slurp solution" (which I'm okay with for this purpose). The aspects I needed to solve:

    1. Completely get away from the java.io.NotSerializableException problem, even when the JSON text defines nested containers
    2. Work for both map and array containers
    3. Support LAX parsing (the most important part, for my situation)
    4. Easy to implement (even with the awkward nested constructors that obviate @NonCPS)

提交回复
热议问题