Using Compact Serializer Generator
Allows you to generate compact classes for your POJOs.
Creating Schemas for Business Objects
Let’s assume you have the following entities in your application:
-
Student
-
ID: an integer
-
Name: a string
-
-
Classroom
-
ID: an integer
-
Students: an array of
Student
.
-
-
School
-
ID: an integer
-
Classrooms: an aray of
Classroom
.
-
The schema definitions are as follows:
Schema definitions contain following information:
-
A description of the content of the
Student
,Classroom
, andSchool
compact classes. -
The namespaces for the schema files, identified using
serializer.namespace
.
Generating Compact Classes from Schemas
To generate compact classes, use the following command:
This generates the classes in the current working directory. To save them to a different directory, use the following command, where <my_directory>
identifies the directory in which you want to generate the classes:
The following classes are generated:
-
StudentSerializer.java
-
SchoolSerializer.java
-
ClassroomSerializer.java
in org/example/serializers
directory.
Creating Compact Serialization Configuration
You can configure the configuration options in any of the following ways:
-
Java Configuration
-
XML Configuration
-
YAML Configuration
In the following code, we use the Java configuration to register the generated compact classes:
Using SQL Support
To use SQL support, you must create a mapping, write to the map, and write to the map using a Java client. You can then check the type of the created records and query the map using the Java client.
These steps are described in the following sections.
Creating Mapping
If the keys or values in a map use the Compact format, provide the following options when creating the mapping:
-
keyCompactTypeName
-
valueCompactTypeName
You can execute the SQL either using CLC or the Java Client.
Checking the Created Records' Type
As we used the Compact
format when creating the map, we must check whether the format uses the correct type
. We do this as follows:
clc map entry-set --name students --show-type -f table
__key | __key_type | this | this_type | id | name
joe | STRING | > | COMPACT | 1 | Joe Dalton
william | STRING | > | COMPACT | 2 | William Dalton
Averell | STRING | > | COMPACT | 4 | Averell Dalton
jack | STRING | > | COMPACT | 3 | Jack Dalton
As you can see, all records are defined as COMPACT
in the this_type
column.