Skip to content

DTO Classes

Steve Hannah edited this page Jun 20, 2016 · 1 revision

A DTO (Data transfer object) is an object that can be transferred between the client and the server. DTO classes are defined in the "shared" project under the xxx.dto namespace (where xxx is the base package of your project). Any object that you wish to "put on the wire" must be a DTO class (or another type that Codename One knows how to serialize).

Some properties of DTO objects:

  1. Must contain a default public constructor

  2. Any properties that you want to be able to serialize must be either public, or include public accessors and getters following the java beans naming conventions.

  3. Properties can be any of:

    1. Other DTO objects.

    2. Primitives (e.g. int, float, etc…​)

    3. Boxed primitives (e.g. Integer)

    4. Strings

    5. Dates

    6. Arrays (where the component type is an acceptable DTO property type)

    7. java.util.List (where the elements are acceptable DTO property types)

    8. java.util.Map (where the elements are acceptable DTO property types)

The CN1DataMapper library is used to perform compile-time reflection, and generate "mappers" for all DTO objects so that Codename One is able to automatically serialize and deserialize these types at runtime. The "server" Spring project includes a message converter that also knows how to serialize and deserialize these types automatically.

Updating DTO Classes

Changes to the "shared" project (where all DTO classes reside) will not be picked up by the client and server projects until you run the "install-shared" ANT target. So, after making any changes to these classes, you should run this ant task.