Skip to content

Latest commit

 

History

History
84 lines (62 loc) · 2.5 KB

QuickStart.md

File metadata and controls

84 lines (62 loc) · 2.5 KB

Quick Start

Maven

Maven Central

<dependency>
    <groupId>com.envimate.mapmate</groupId>
    <artifactId>core</artifactId>
    <version>${mapmate.version}</version>
</dependency>

Compiler Configuration

MapMate uses method parameter names to construct your objects, hence requires you to compile with parameter names. This is configured by passing the -parameters flag to the java compiler.

Maven configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgs>
            <arg>-parameters</arg>
        </compilerArgs>
    </configuration>
</plugin>

For your IDE it's as simple as having it compile using the -parameters command-line argument of java compiler.

Minimal Configuration

MapMate needs to know the package where your Custom Primitives and Serialized Objects reside. MapMate is also unaware of the chosen format, hence needs to be configured with (Un)marshaller to deal with the format conversion.

If you are following the default conventions, and have chosen JSON as format, along with Gson as marshaller, here is the minimal configuration you need to get access to serializer and deserializer

final MapMate mapMate = MapMate.aMapMate(THE_PACKAGE_NAME_TO_SCAN_RECURSIVELY)
        .usingJsonMarshallers(new Gson()::toJson, new Gson()::fromJson)
        .build();

Read the User Guide for detailed description on how to further configure the MapMate instance.

Serialization

now serializing the object

Email EMAIL = Email.deserialize(
            EmailAddress.fromStringValue("sender@example.com"),
            EmailAddress.fromStringValue("receiver@example.com"),
            Subject.fromStringValue("Hello"),
            Body.fromStringValue("Hello World!!!")
    );

mapMate.serializeToJson(EMAIL);

will produce

{
  "receiver": "receiver@example.com",
  "body": "Hello World!!!",
  "sender": "sender@example.com",
  "subject": "Hello"
}

Deserialization

Using same mapMate instance

mapMate.deserializeJson(EMAIL_JSON, Email.class);

Will produce an object equal to EMAIL.