[ 
https://issues.apache.org/jira/browse/ISIS-1695?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17005844#comment-17005844
 ] 

Oscar Bou commented on ISIS-1695:
---------------------------------

I would suggest to support Project Lombok's @Value [1] annotation as the 
default option for defining Value Objects in Apache Isis.

Seems the most common way on Spring Boot (with Spring Data - JPA will also need 
the @Embeddable annotation).

Also on Lagom[2], which I'm recently using on another project. Being a very 
opinionated framework and originally based on Scala, with all its functional 
background, immutability is a key issue, so you will find an interesting 
discussion in [2] about how to better implement immutable value objects with 
Java.

A more complete option than Lombok's @Value would be the Immutables[3] library, 
which also supports immutable collections, despite a better implementation of 
immutable collections seems to be [4] (see discussion in [2]).

Summarizing, supporting at least Lombok's @Value on viewers would be enough for 
most use cases.

I would not recommend to introduce specific Isis annotations unless strictly 
necessary, to ease the porting of already implemented bounded contexts and ease 
the path to "automagically" create a Web UI and REST API for them, with minimal 
changes.

 

HTH,

Oscar

[1][https://projectlombok.org/features/Value]

[2][https://www.lagomframework.com/documentation/1.6.x/java/Immutable.html]

[3][https://immutables.github.io|https://immutables.github.io/]

[4][https://github.com/hrldcpr/pcollections]

 

> Support value types (simple ones at least) as a first-class citizen
> -------------------------------------------------------------------
>
>                 Key: ISIS-1695
>                 URL: https://issues.apache.org/jira/browse/ISIS-1695
>             Project: Isis
>          Issue Type: New Feature
>            Reporter: Daniel Keir Haywood
>            Priority: Minor
>             Fix For: 2.0.0
>
>
> I would like to reintroduce value types as a first-class citizen, but without 
> requiring the developer to have to write lots of code to teach DataNucleus, 
> Wicket and the RO viewer about these.
> I don't have a general solution in mind on how to do this.
> However, for very simple value types that are just a type-safe wrapper around 
> a single field (eg Password, or Money, or Temperature, or Email say), then 
> perhaps there might be a way to support this, eg :
> public class Temperature implements 
> org.apache.isis.valuetypes.Value<BigDecimal> {
>     public Temperature(BigDecimal value) \{ ... }
>     BigDecimal getValue() \{ ... }
> }
>  
>  or
>  
>  @Value(underlying=BigDecimal.class)
>  public class Temperature \{ ... }
> The idea here is that the framework would treat any instance of this custom 
> value type as if it were the underlying type (BigDecimal in the case above). 
> It would also be possible to apply validations to the value type that would 
> apply everywhere it is used as a property/parameter.
>  
> We would expect these value types to be immutable, and (although this can't 
> be expressed in an interface), would expect there to be a public 1-arg 
> constructor of the appropriate type, and a package-local "getValue()" method. 
>  These allow the framework to marshal values in and out of the value type.
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to