From 13169a275ebc6cb5c46dea6d1a2faf5f02f4c3ed Mon Sep 17 00:00:00 2001 From: kmetin Date: Tue, 26 Sep 2023 15:49:25 +0300 Subject: [PATCH] init compact serializer tutorial --- .../using-compact-serializer-generator.adoc | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/docs/modules/ROOT/pages/using-compact-serializer-generator.adoc b/docs/modules/ROOT/pages/using-compact-serializer-generator.adoc index cd24b62f..de45d996 100644 --- a/docs/modules/ROOT/pages/using-compact-serializer-generator.adoc +++ b/docs/modules/ROOT/pages/using-compact-serializer-generator.adoc @@ -16,6 +16,7 @@ Let's assume we have the following entities in our application: * Student ** Name ** Number +** List of AssignedLessons * Teacher ** ID ** Name @@ -43,8 +44,8 @@ classes: type: string - name: number type: int16 - - name: assignedLessons - type: com.lesson[] + - name: AssignedLessons + type: com.education.Lesson[] external: true - name: advisor type: Teacher @@ -91,13 +92,47 @@ Schema definitions can contain following information: * specify a namespaces for schema files using `namespace`. * referenced classes (in this example `com.lesson`) that are not present in the given schemas. * referenced to an internal class (in this example `Student` reference to `Teacher` in the same schema file). +* an external schema is used and specified with `external: true`, assuming `com.education.Lesson` is already defined in the project. == Generating POJOs and Compact Classes from Schemas +To be able to generate compact classes, following command can be used: +[source,bash] +---- +clc serializer generate school.yaml -l java +---- + +This will generate the classes into the current working directory. If you want to save them to another directory you can append `-o ` to the command. After running the command, following classes will be generated: + +* `Student.java` +* `Teacher.java` +* `School.java` +* `Classroom.java` + +User should copy the generated classes to their own packages in their codebase. == Creating Compact Serialization Configuration +The output of the `generate` command lists configuration options, there are 3 different ways to configure: + +* Java Configuration +* XML Configuration +* YAML Configuration + +Let's use Java configuration this time and use the following code to register the generated compact classes: + +[source,java] +---- +ClientConfig config = new ClientConfig(); +config.getSerializationConfig().getCompactSerializationConfig().setSerializers( + new com.rooms.Classroom.Serializer(), + new com.people.Student.Serializer(), + new com.people.Teacher.Serializer(), + new com.education.School.Serializer() +); +---- + == Writing to a Map using Java Client == Querying the Map using Python Client