Java Reference
In-Depth Information
Lessons learned (JSON)
1. The JsonSlurper class has a parseText method for working with JSON
formatted strings.
2. The JsonBuilder class generates JSON strings using the same mechanism as
the XmlSlurper .
This completes the tour of Groovy features that can be added to Java applications regard-
less of use case.
Lessons learned (Groovy features used in Java)
1. When Groovy access a POJO it can use the map-based constructor as though it
were a POGO.
2. EveryoperatorinGroovydelegatestoamethod,andifthatmethodisimplemented
in a Java class the operator in Groovy will still use it. This means you can do oper-
ator overloading even in a Java class.
3. The Groovy JDK documents all the methods that Groovy adds to the Java standard
API through metaprogramming.
4. GroovyASTtransformationscanonlybeappliedtoGroovyclasses,buttheclasses
can be mixed with Java in interesting ways. This chapter includes examples of
@Delegate , @Immutable , and @Singleton .
4.7. Summary
This chapter reviewed many ways that Groovy can help Java at the basic level, from POJO
enhancements to AST transformations to building XML and more. I'll use these techniques
in future chapters wherever they can help. I'll also review other helpful techniques along
the way, though these are most of the major ones.
The next couple of chapters, however, change the focus. Although mixing Java and Groovy
is easy and is a major theme of this topic, some companies are reluctant to add Groovy
to production code until their developers have a certain minimum comfort level with the
Search WWH ::




Custom Search