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.json
ArtifactId

ArtifactId

jsonauto
Last Version

Last Version

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

Dependencies

compile (2)

Group / Artifact Type Version
net.pwall.json : jsonutil jar 2.0
net.pwall.util : javautil jar 2.0

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
2.3
2.2
2.1
2.0