<dependency>
<groupId>com.envimate.mapmate</groupId>
<artifactId>core</artifactId>
<version>${mapmate.version}</version>
</dependency>
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.
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.
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"
}
Using same mapMate
instance
mapMate.deserializeJson(EMAIL_JSON, Email.class);
Will produce an object equal to EMAIL
.