Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JodaTime Domain properties are not listed as Persistent Properties #27

Open
puneetbehl opened this issue Feb 9, 2018 · 1 comment
Open
Assignees

Comments

@puneetbehl
Copy link
Member

puneetbehl commented Feb 9, 2018

Grails 3.3.2
JDK 8

For example we have a domain User.groovy

package demoapp

import org.joda.time.LocalDate
import org.jadira.usertype.dateandtime.joda.PersistentDateTime

class User {

    LocalDate dateOfBirth

    static constraints = {
	dateOfBirth type: PersistentDateTime
    }
}

Now, when we run the following test it should pass:

    void "test joda time property on persistentEntity"() {
		when:
		assert domain.properties != null
        PersistentEntity persistentEntity = User.gormPersistentEntity
        List<PersistentProperty> properties = persistentEntity.persistentProperties
		
        then: "Joda property found on persistent entity"
        properties.any {it.type == LocalDate}
    }
@puneetbehl puneetbehl self-assigned this Feb 9, 2018
@longwa
Copy link

longwa commented May 4, 2018

For unit testing, you need to register the CustomTypeMarshaller for the SimpleMap by adding this to your application.groovy:

grails.gorm.custom.types = [
    new SimpleMapJodaTimeMarshaller(LocalDate),
    new SimpleMapJodaTimeMarshaller(LocalDateTime),
]

The plugin should probably add this configuration automatically. This used to be done inside the initialize method on the SimpleMapJodaTimeMarshaller, however in GORM 6 and later, the registerCustomType method is no longer static so it must be done via the configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants