Posts

Showing posts from 2015

Grails and Hibernate: Saving emoticons ( unicode ) to MYSQL.

Image
We built a  Grails  application that uses a mail plugin, to send and retrieve emails from mail servers. The plugin employed a scheduled job to retrieve and store the emails on a MySql database table. Initially everything worked as specified until recently when I noticed that some mails were not saved to MYSQL. The error message from MYSQL was 'incorrect string value' bla bla bla.... On close examination, I noticed that the troublesome emails contained emoticons (unicode characters). The unicode characters were responsible for my troubles :( The issue I dug through the MySQL documentation and learnt that my MySQL instance was having a hard time accepting those unicode characters because the database encoding was set to "utf-8". Solution To solve the problem required a change of the mysql default encoding from "utf-8" to "utf8mb4" . Note :We used a MySQL version of 5.6.13 but this solution will also apply to MySQL ve

How to upgrade Grails 2 applications and plugins to Grails 3

Image
How to upgrade Grails 2 applications and plugins to work with Grails 3  The  Grails  framework is a web framework  for developing dynamic websites. It has been recently upgraded to version 3.0 and the upgrade has introduced breaking changes. According to the grails documentation, Grails 3.0 is a complete ground up rewrite of Grails and introduces new concepts and components for many parts of the framework. The 'rewrite' part means that a lot has changed, including class packages. This means that your plugin will break if it imports any of the Grails API packages that have been moved. Although the Grails documentation provides a guide for upgrading applications and plugins, it does not provide information about all the Grails API package changes. To save software development time, please find some of the package changes below. Grails 2 Grails 3 org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap grails.web.servlet.mvc.GrailsParameterMap org.cod

Parsing and binding date formats from params in Grails.

Image
" Grails is a powerful web framework for the Java platform aimed at multiplying developers' productivity" - grails. We recently decided to rewrite some parts of our software  ( written in grails )as web applications.  The reason we made that decision is something I hope to write about soon. The task required us to send JSON strings (POST request) that contain datetime information along with other bits for data to the server.  To bind a date string from the 'param' seamlessly ( without writing extra code to extract the date in your controller) you need to add the following to your grails config file ( config.groovy or application.yml ). grails.databinding.dateFormats = [ "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "yyyy-MM-dd'T'HH:mm:ss.SSSZ" ,'yyyy-MM-dd HH:mm:ss.S','MMddyyyy' ] With the above configuration in place, there was no need to extract the date and bind it manually to the domain class or comma