This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Groovy and the fly likes Weird behaviour with json builder within a mixin - is this a bug ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Weird behaviour with json builder within a mixin - is this a bug ?" Watch "Weird behaviour with json builder within a mixin - is this a bug ?" New topic
Author

Weird behaviour with json builder within a mixin - is this a bug ?

william Woodman
Greenhorn

Joined: Apr 23, 2012
Posts: 12
weird thing - i was mucking about with a mixin class - where i was adding bahaviour to persist a class into mongoDB - i'm using groovy 2.1

i define a simple test class like this



this all works as expected and the bldr generates the right string

my persistence mixin looks like this at the mo




when i run the code and use the first form and pass 'this' which is an instance of MyClass as this is a mixin - then i get am empty Json string - not the right answer - but the other forms work

then out of perversity - if i change the class definition to add Cloneable like this



- i dont really want to have to have the object to save to have to to implement Cloneable. so why does the first form - new JsonBuilder (this) return me an {} json string - but the second form - new JsonBuilder(this.clone()) works just fine - very weird - has any one got any ideas as to why its doing this

within the mixin - this is an instance of MyClass as expected - here is the trace of the working cloneable version - and as you can see the last line bldr: is the correct form



here is the same trace using removing the Cloneable and just passing this to the builder in the mixin - i'm using groovy 2.1




 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Weird behaviour with json builder within a mixin - is this a bug ?
 
Similar Threads
Constructor
1000 characters
Scala mixin behavior
problem with groovy swt: stuck with bind node processing and ComputedValues
Unfamiliar Scala syntax