Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
william Woodman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic