Decoding HTML special characters

I am writing a Service Manager that calls a Web API to get the values from various devices.
The api returns values that may have html encoded characters (e.g. “70& deg; F” ). I would like to decode the encoded characters so “70& deg; F” is displayed as “70° F”. I’m trying to do this in the device handler but I can’t seem to get it to work with “°”.

I am using:
def val = new XmlSlurper().parseText("& deg;")

However, the above works with other encoded characters like “& amp;” and “& gt;”.

NOTE: I added a space after the “&” (e.g. "& ") so that the values would not be decoded in this post.


Recently encountered a similar issue, and decided is was easier to use BASE64 rather than fight with Html Entities in Groovy. Yes a longer string to send, but it works.

In your api do the BASE64 encoding, then in Groovy
def txt = some_string.decodeBase64()


Unfortunately, I don’t have access to the API so I can’t modify that.