JSON Auto Serialize/deserialize

Auto serialization/deserialization classes for jsonutil

License

License

Categories

Categories

Net Auto Application Layer Libs Code Generators JSON Data
GroupId

GroupId

net.pwall.util
ArtifactId

ArtifactId

jsonauto
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

JSON Auto Serialize/deserialize
Auto serialization/deserialization classes for jsonutil
Project URL

Project URL

https://github.com/pwall567/jsonauto
Source Code Management

Source Code Management

https://github.com/pwall567/jsonauto.git

Download jsonauto

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
net.pwall.util : jsonutil jar 1.4
net.pwall.util : javautil jar 1.3

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

jsonauto

JSON auto serialize / deserialize from / to Java.

Background

I am not a big fan of reflection-based automatic serialization and deserialization of Java objects to and from JSON - reflection is always slower than explicit serialization and it sometimes gives unexpected results. But I know that many people prefer it so I've added it as an optional additional package to my jsonutil library.

Usage

To serialize any object:

JSONValue json = JSONSerializer.serialize(object);
String text = json.toJSON();

Nested objects are handled automatically, as are many of the commonly-used classes from java.lang and java.util (more documentation to follow).

To deserialize:

JSONValue json = JSON.parse(text);
UserClass userObject = JSONDeserializer.deserialize(UserClass.class, json);

See the JavaDoc for more information.

Annotations

Annotations are available to specify that a field is to be ignored, or always included even if null (the default behaviour is to ignore null fields). The field name may also be specified.

  • @JSONIgnore - never serialize
  • @JSONAlways - always serialize
  • @JSONName("name") - use the specified name when serializing

Maven

The library is in the Maven Central Repository; the co-ordinates are:

<dependency>
  <groupId>net.pwall.util</groupId>
  <artifactId>jsonauto</artifactId>
  <version>1.0</version>
</dependency>

Versions

Version
1.0