dataj-core

null

License

License

Categories

Categories

Data
GroupId

GroupId

org.dataj
ArtifactId

ArtifactId

dataj-core
Last Version

Last Version

0.3
Release Date

Release Date

Type

Type

jar
Description

Description

dataj-core
null
Project URL

Project URL

http://dataj.org
Source Code Management

Source Code Management

https://github.com/alek-sys/dataj.git

Download dataj-core

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
com.squareup : javapoet jar 1.9.0
com.google.guava : guava jar 22.0

runtime (1)

Group / Artifact Type Version
com.google.auto.service : auto-service jar 1.0-rc3

test (6)

Group / Artifact Type Version
com.google.testing.compile : compile-testing jar 0.12
org.junit.jupiter : junit-jupiter-api jar 5.0.0
com.github.javaparser : javaparser-core jar 3.3.4
com.google.code.findbugs : jsr305 jar 3.0.2
org.junit.jupiter : junit-jupiter-engine jar 5.0.0
org.junit.platform : junit-platform-launcher jar 1.0.0

Project Modules

There are no modules declared in this project.

dataj - simple data classes for Java 9

dataj is a library (an annotation processor to be exact) which helps to generate data classes for Java. The zen of dataj is: no magic, 100% compatibility, and full control.

What is a data class?

A data class is basically a Java class with defined getters, setters and methods to check object equality (equals and hashCode). It is quite common to have this combination of methods for POJO (Plain Old Java Object), DTOs (Data Transfer Objects) and data entities. All these classes can be called data classes.

Quickstart

Gradle

In build.gradle add a new dependency:

compile 'org.dataj:dataj-core:0.1'

Maven

In pom.xml add a new dependency:

<dependency>
    <groupId>org.dataj</groupId>
    <artifactId>dataj-core</artifactId>
    <version>0.1</version>
</dependency>

Intellij IDEA

If you want to get full IDE support from IDEA you need to enable Annotation processing. Open settings and in Build, Execution, Deployment > Compiler > Annotation Processors enable annotation processing for the project. Also you can specify what folders should annotation processor use to put generated sources to. This folder should then be marked as Generated sources root to enable compilation and all IDE features.

FAQ

How does it work?

dataj is an annotation processor so it kicks in on annotation processing phase of building your project. It scans for all classes annotated with @Data annotation and generates a data class for it in the same package. Then you can use generated class instead of the original class wherever you need. Consider it to be a drop-in replacement. You can even commit generated class into your source control system, if you'd like.

The original class remains in place, however it is only used as a blueprint to generated a data class. The generated class does not reference the original class in any way.

Where is generated source code stored?

Depends from the configuration. In Intellij IDEA you can configure where the files will go - source root or output folder. You can use any, just make sure target folder is marked as Generated Sources Root in your module configuration.

What is the name of the generated class?

It is <class annotated with @Data>Data. E.g. for class

@Data
class Person {
    ...fields
}

dataj will generate class

final class PersonData {
    ...constructor
    ...getters
    ...setters
    ...equals
    ...hashcode
}

with getters, setters, equality check (equals and hashcode) methods.

Can I edit generated code?

You probably don't want to do that as it will be re-generated on next compilation.

Is it compatible with Java 9?

Yes, generated code 100% compatible with Java 9.

Why is generated class final?

This is generally considered to be not very good idea. If you need to extend it - probably this is not a simple DTO.

Why not to use Lombok?

Lombok is truly amazing annotation processor which helps bring a lot of new and cool features into Java. Data classes is just one of them. However, it does quite a lot of hacking of Java compilation process and tries to change generated bytecode on the fly. Also this requires support from IDE, which is although provided by Lombok team. Because of quite a complex implementation and deep integration with Java compiler it is quite tricky to update it to support Java 9.

So generally if you are using Lombok and you are happy with this - you probably don't need dataj. However, if you are looking for something very simple, lightweight and compatible with Java 9 - you might be interested in dataj.

How does it work?

Following the zen, basic principle of dataj is "Do not hack the compiler, generate the code". Generated code is easy to review, it can be committed to your VCS, or generated on the fly - up to you. Because it uses simple Java annotation processing there is no need in extra plugins for any of the build systems - Gradle and Maven work with it out of the box. Similar for IDEs, annotation processing and working with generated code supported by all major IDEs - Intellij IDEA, Eclipse and NetBeans. No need to install plugins or use special tools!

Compatibility

dataj supports Java 7, 8 and 9.

Versions

Version
0.3
0.2
0.1