The new version IntelliJ IDEA 2016.2 is out! It includes a new feature to support font ligatures. It looks very promising, so I downloaded and installed the font FiraCode. But I noticed rough edges in the font.
For several of my projects I required a list where input items could be dynamically added and removed. Because i saw uses for this over and over i created a component which i’m sharing with you here.
Suppose we want to support partial JSON responses in our Ratpack application. The user must send a request parameter with a list of fields that need to be part of the response. In our code we must use the value of the request parameter and output only the given properties of an object. We implement this logic using a custom renderer in Ratpack. Inside the renderer we can get access to the request parameters of the original request.
We can use the environment variable
SPRING_APPLICATION_JSON with a JSON value as configuration source for our Grails 3 application. The JSON value is parsed and merged with the configuration. Instead of the environment variable we can also use the Java system property
Ratpack has a lot of options to add configuration data to our application. We can use for example YAML and JSON files, properties, environment variables and Java system properties. Groovy has the
ConfigSlurper class to parse Groovy script with configuration data. It even supports an
environments block to set configuration value for a specific environment. If we want to support Groovy scripts as configuration definition we write a class that implements the
We have many ways to provide configuration properties to a Spring (Boot) application. We can add our own custom configuration properties format. For example we can use Groovy’s
ConfigObject object to set configuration properties. We need to read a configuration file using
ConfigSlurper and make it available as a property source for Spring. We need to implement two classes and add configuration file to support a Groovy configuration file in a Spring application.
To define configuration sources for our Ratpack application we have several options. We can set default properties, look at environment variables or Java system properties, load JSON or YAML formatted configuration files or implement our own configuration source. When something goes wrong using one of these methods we want to be able to handle that situation. For example if an optional configuration file is not found, we want to inform the user, but the application must still start. The default exception handling will throw the exception and the application is stopped. We want to customise this so we have more flexibility on how to handle exceptions.
Adding logging support to a class in Groovy is easy. We can choose to add SLF4J, Log4j, Log4j2, Apache Commons or Java Util Logging to our class. The default implementation of the Abstract Syntax Tree (AST) transformation is to add a
log field of the correct type. As category name the complete class name (including the package) is used. We can change the name of the field with the
value attribute. To alter the category name we use the attribute
Groovy adds to
Map objects the
toMapString method. With this method we can have a String representation of our
Map. We can specify an argument for the maximum width of the generated
String. Groovy will make sure at least the key/value pairs are added as a pair, before adding three dots (
...) if the maximum size is exceeded.
def course = [
name: 'Groovy 101',
location: 'The Netherlands']
assert course.toMapString(15) == '[name:Groovy 101, ...]'
assert course.toMapString(25) == '[name:Groovy 101, teacher:mrhaki, ...]'
As mentioned in a previous post we can use the
toListString method to represent a
List as a
def names = ['mrhaki', 'hubert']
assert names.toListString(5) == '[mrhaki, ...]'
Written with Groovy 2.4.7.