I have many objects with a property description where is like this:
description: "This is <strong>my description<strong>"
I build a list A with this objects in a method and I return.
The other list B who is receiving the A list, it hides the html tags.
When I access the same object of list A in list B, the description is like this:
description: "This is my description"
I don’t know if there is a property on maps or lists that lose HTML content when transfering one to another.
Can someone help me?
Code:
def bla {
def mentions = [:]
mentions = extractMentionsFromJSON(def json)
println " 3 " + mentions[0].description
}
def extractMentionsFromJSON(def json){
def result = []
json.response.docs.each {
try {
Mention m = new Mention()
m.title = json.highlighting[m.id].'title'.getAt(0)
println "1 title --> " + m.title
println "1 title --> " + m.title.getClass()
m.description = json.highlighting[m.id].'description'.getAt(0)
println "1 description --> " + m.description
println "1 description --> " + m.description.getClass()
result.add(m)
} catch (Exception e) {
println "ERROR"
}
println " 2 "
result.each { println it.title}
return result
}
}
In the print “1” and “2” the object description and title have the correct attributes with html content.
In the prin “3”, no html content.
When you pass a list around in Groovy or Java, you don’t pass a copy of the list and everything in it. You just pass a reference to the same list and the same items inside it.
If you change these objects in a method, any other place with a reference to them will see the changes. You’ll need to explicitly make copies of these objects instead.
(I’m sorry if the answer is too vague and generic, but you haven’t given enough information about your code to make a proper sample.)