dev-resources.site
for different kinds of informations.
DataBinding and GORM objects
Published at
5/20/2020
Categories
grails
groovy
gorm
Author
joemccall86
Author
11 person written this
joemccall86
open
In Groovy, you are able to do this:
class Widget {
String name
}
def widget = new Widget(name: '')
assert widget.name == ''
When this widget is a GORM object (in a Grails application), the default configuration doesn’t allow for this:
// Inside grails-app/domain
class PendingDeletion {
String name
String path
}
// Elsewhere in code
def pendingDeletion = new PendingDeletion(name: 'foo', path: '')
assert pendingDeletion.path == '' // Fails; pendingDeletion.path is null
This is because the default configuration instructs the Grails data-binder to convert empty strings to null 1.
I’m not exactly sure why this is the default. In order to make the above snippet work in your Grails application, specify the following in application.yml:
grails:
databinding:
convertEmptyStringsToNull: false
This allows the GORM map constructor to behave the same as a normal POGO map constructor.
Alternatively, just do not use the GORM map constructor when the field values can be null.
gorm Article's
26 articles in total
Gorm: Sneak Peek of Custom Data Types
read article
GORM, PostgreSQL & Atlas
read article
Gorm Pagination With Ease
read article
How to Use Arrays as Parameters in Golang?
read article
Basic CRUD Operations Using Golang, Gin Gonic, and GORM
read article
GORM and Goose Migrations
read article
Gin + Gorm Practical Guide, Implementing a Simple Q&A Community Backend Service in One Hour
read article
A secret weapon to improve the efficiency of golang development, a community backend service was developed in one day
read article
Building CRUD Operations in Golang 🎉
read article
Some GORM Tips and Notes
read article
Gorm level UP: how to upgrade and start to use Gorm v2
read article
5chan API - Golang, GORM, Go-fiber
read article
Pagination using Gorm scopes
read article
GOlang URL shortener service using postgres, redis, bulma
read article
RestFull API Detailing
read article
Daily Blog
read article
Rest API Database Blog Post
read article
Prevent updating query updates all records in GORM
read article
Init project
read article
Creating a complete golang rest api from zero to Hero
read article
ตัวอย่างการสร้าง Many to Many Association ผ่าน GORM
read article
DataBinding and GORM objects
currently reading
Creating an opinionated GraphQL server with Go - Part 4
read article
Creating an opinionated GraphQL server with Go - Part 3
read article
Grails: Mocking domain objects/criteria that reference Joda Time objects
read article
Go's ORM framework GORM best practices indefinite parameter usage
read article
Featured ones: