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

Feature request: custom PersistentPropertyType with converter #236

Open
kktuax opened this issue Aug 17, 2015 · 0 comments
Open

Feature request: custom PersistentPropertyType with converter #236

kktuax opened this issue Aug 17, 2015 · 0 comments

Comments

@kktuax
Copy link

kktuax commented Aug 17, 2015

It would be great to support custom domain model types. Now with JPA you can define custom model property types, and a javax.persistence.Converter, for example for storing a joda-time Duration as a Long value:

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

import org.joda.time.Duration;

@Converter(autoApply = true)
public class DurationConverter implements AttributeConverter<Duration, Long>{

    @Override
    public Long convertToDatabaseColumn(Duration value) {
        if(value!=null){
            return value.getMillis();
        }
        return null;
    }

    @Override
    public Duration convertToEntityAttribute(Long value) {
        if(value!=null){
            return Duration.millis(value);
        }
        return null;
    }

}

It would be great to have some way of editing this type of fields. Detecting automatically JPA's converters I imagine it could be challenging, but maybe it could be achieved with something similar to FieldValueRenderer in formView.

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

1 participant