com.github.zerkseez.gwtpojo-codegen

POJO-JSON serialization for GWT

Лицензия

Лицензия

Категории

Категории

GWT (Google Web Toolkit) Взаимодействие с пользователем Веб-фреймворки
Группа

Группа

com.github.zerkseez
Идентификатор

Идентификатор

gwtpojo-codegen
Последняя версия

Последняя версия

1.0.0-ALPHA
Дата

Дата

Тип

Тип

jar
Описание

Описание

com.github.zerkseez.gwtpojo-codegen
POJO-JSON serialization for GWT
Система контроля версий

Система контроля версий

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

Скачать gwtpojo-codegen

Как подключить последнюю версию

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

Зависимости

compile (9)

Идентификатор библиотеки Тип Версия
com.fasterxml.jackson.core : jackson-core jar 2.5.4
com.fasterxml.jackson.core : jackson-annotations jar 2.5.4
com.fasterxml.jackson.core : jackson-databind jar 2.5.4
com.github.zerkseez : generic-reflection jar 1.1.0
com.github.zerkseez : gwtpojo-annotations jar 1.0.0-ALPHA
com.github.zerkseez : gwtpojo-core jar 1.0.0-ALPHA
com.google.guava : guava jar 20.0
com.google.gwt : gwt-user jar
org.reflections : reflections jar 0.9.10

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12

Модули Проекта

Данный проект не имеет модулей.

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

Версии библиотеки

Версия
1.0.0-ALPHA