This project demonstrates how to use Java + Elm with the help of FunctionalJ.io.
Add pom.xml
dependency to functionalj-all
version 0.5.8.0
or newer.
<dependency>
<groupId>io.functionalj</groupId>
<artifactId>functionalj-all</artifactId>
<version>0.5.8.0</version>
</dependency>
See on GitHub
Add Java classes specifying the data model - either Struct or Choice type.
Also add the @Elm
annotation to specify that Elm code should be generated.
baseModule
specifies module in the generated Elm code -- default to FROM_PACAKGE_NAME
.
generatedDirectory
specifies the directory for the generated code -- default to ./generated/elm/
.
@Struct
@Elm(baseModule = "", generatedDirectory = "elm/src/")
static interface PersonModel extends RestData {
@Nullable String id();
@Required String firstName();
@Required String lastName();
@Nullable String nickName();
@Required Cape cape();
}
@Choice
@Elm(baseModule = "", generatedDirectory = "elm/src/")
static interface CapeModel {
void Color(String color);
void None();
}
See on GitHub
That is it!!!!
How the JavaElm should generates two Elm file: Person.elm and Cape.
These file contains the declaration of those data types as well as the encoder/decoder of the data types as well as the list of those types.
Enjoy Coding!