GWTPojo Parent POM

POJO-JSON serialization for GWT

License

License

Categories

Categories

GWT (Google Web Toolkit) User Interface Web Frameworks
GroupId

GroupId

com.github.zerkseez
ArtifactId

ArtifactId

gwtpojo-parent
Last Version

Last Version

1.0.0-ALPHA
Release Date

Release Date

Type

Type

pom
Description

Description

GWTPojo Parent POM
POJO-JSON serialization for GWT
Project URL

Project URL

https://github.com/zerkseez/gwtpojo
Source Code Management

Source Code Management

https://github.com/zerkseez/gwtpojo/tree/master

Download gwtpojo-parent

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.zerkseez/gwtpojo-parent/ -->
<dependency>
    <groupId>com.github.zerkseez</groupId>
    <artifactId>gwtpojo-parent</artifactId>
    <version>1.0.0-ALPHA</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.zerkseez/gwtpojo-parent/
implementation 'com.github.zerkseez:gwtpojo-parent:1.0.0-ALPHA'
// https://jarcasting.com/artifacts/com.github.zerkseez/gwtpojo-parent/
implementation ("com.github.zerkseez:gwtpojo-parent:1.0.0-ALPHA")
'com.github.zerkseez:gwtpojo-parent:pom:1.0.0-ALPHA'
<dependency org="com.github.zerkseez" name="gwtpojo-parent" rev="1.0.0-ALPHA">
  <artifact name="gwtpojo-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.github.zerkseez', module='gwtpojo-parent', version='1.0.0-ALPHA')
)
libraryDependencies += "com.github.zerkseez" % "gwtpojo-parent" % "1.0.0-ALPHA"
[com.github.zerkseez/gwtpojo-parent "1.0.0-ALPHA"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

  • gwtpojo-annotations
  • gwtpojo-core
  • gwtpojo-codegen
  • gwtpojo-maven-plugin
  • gwtpojo-bom

GWTPojo

POJO-JSON serialization for GWT

About

GWTPojo provides an alternative solution to GWT's AutoBean framework for POJO-JSON serialization/deserialization; but unlike AutoBean, GWTPojo allows the client and the server code to share the same Pojo classes. GWTPojo also provides support for generics (except for wildcards) and partial support for polymorphism using Jackson's @JsonTypeInfo and @JsonSubTypes annotations.

Features

  • Sharing Pojo implementation between client and server
  • Generics support (except for wildcards)
  • Partial polymorphism support (using Jackson's @JsonTypeInfo and @JsonSubTypes annotations)

Usage

To share pojo classes between client and server, it is highly recommended to put all your pojo classes into a separate "model" jar and have both your client and server to reference the model jar.

pom.xml of your client

<project>
    ...

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.zerkseez</groupId>
                <artifactId>gwtpojo-maven-plugin</artifactId>
                <version>${gwtpojo.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <!-- Add mycompany-model as a dependency for gwtpojo-maven-plugin -->
                    <dependency>
                        <groupId>com.mycompany</groupId>
                        <artifactId>mycompany-model</artifactId>
                        <version>${project.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            ...
        </plugins>
    </build>

    <dependencies>
        <!-- Add mycompany-model as a dependency the client as well -->
        <dependency>
            <groupId>com.mycompany</groupId>
            <artifactId>mycompany-model</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <!-- If the source code for mycompany-model is in a separate jar, include it as well -->
        <dependency>
            <groupId>com.mycompany</groupId>
            <artifactId>mycompany-model</artifactId>
            <version>${project.version}</version>
            <classifier>sources</classifier>
            <scope>provided</scope>
        </dependency>
        <!-- gwtpojo-core is also needed -->
        <dependency>
            <groupId>com.github.zerkseez</groupId>
            <artifactId>gwtpojo-core</artifactId>
            <scope>provided</scope>
        </dependency>
        ...
    </dependencies>
</project>

Client module XML file

<module>
    ...
    <!-- Add reference to GWTPojo -->
    <inherits name="com.github.zerkseez.GWTPojo"/>
    <!-- Add reference to your model module -->
    <inherits name="com.mycompany.Model"/>
    ...
</module>

Java code

GWTPojo will generate a serializer class for each class annotated with @GWTPojo from the model jar. The serializer classes will be generated under the same package as the corresponding pojo classes. For example, the serializer for com.mycompany.model.SamplePojo will be com.mycompany.model.SamplePojoSerializer.

Decorating your pojo class in your model jar with @GWTPojo

@GWTPojo
public class SamplePojo {
   // Declare your class members here
}

Serializing your pojo in your client

SamplePojoSerializer samplePojoSerializer = new SamplePojoSerializer();
JSONValue json = samplePojoSerializer.serialize(samplePojo);
String jsonString = json.toString();

// To serialize List<SamplePojo>
ListSerializer<SamplePojo> listSerializer = new ListSerializer<SamplePojo>(samplePojoSerializer);
JSONValue jsonArray = listSerializer.serialize(listOfSamplePojo);

Deserializing your pojo in your client

SamplePojoSerializer samplePojoSerializer = new SamplePojoSerializer();
SamplePojo pojo = samplePojoSerializer.deserialize(json);

// To deserialize an array of SamplePojo into List<SamplePojo>
ListSerializer<SamplePojo> listSerializer = new ListSerializer<SamplePojo>(samplePojoSerializer);
List<SamplePojo> listOfSamplePojo = listSerializer.deserialize(jsonArray);

Sample project

https://github.com/zerkseez/gwtpojo-sample

License

Apache License, Version 2.0

Versions

Version
1.0.0-ALPHA