Contact us

Java library for JSON deserialization with runtime configured, modifiable and dynamic deserialization rules, utilizing Jackson for low-level operations. JDDL is distributed under Apache License 2.0.
- Read about library on our blog
- Check project on Github
- Check API documentation
- Check latest version on Maven Central
Goals
The library was implemented with the following goals in mind:
- provide simple, readable and flexible rules for object deserialization
- allow for business-level management of deserialized objects
- decouple deserialization specification from the model
- allow customization and extension
Installation
The library is distributed as a jar with all classes defined in com.pretius.jddl
package. The file is available for download from Maven repository.
To use JDDL use the following Maven dependency:
1 2 3 4 5 6 7 |
<dependency> <groupIg>com.pretius</groupId> <artifactId>jddl</artifactId> <version>${jddl-version}</version> </dependency> |
Or check version and dependency specifications at search.aven.org/artifact/com.pretius/jddl.
Usage
A simple plymorphic deserialization using single String field value to determine the class of the deserialized object at runtime.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
public class SampleJddlUsage { public static abstract class ParentType {} public static class Type1 extends ParentType{ String typeName; String fieldString; @Override public String toString() { return "Type1 [typeName=" + typeName + ", fieldString=" + fieldString + "]"; } } public static class Type2 extends ParentType{ String typeName; Double fieldDouble; @Override public String toString() { return "Type2 [typeName=" + typeName + ", fieldDouble=" + fieldDouble + "]"; } } public static class Cont { ParentType i1; ParentType i2; } public static void main(String[] args) { // create a deserializer instance DynamicObjectDeserializer deserializer = new DynamicObjectDeserializer(); // runtime-configure deserialization rules deserializer.addRule(DeserializationRuleFactory.typeByFieldValue(1, "typeName", "myType1String", Type1.class)); deserializer.addRule(DeserializationRuleFactory.typeByFieldValue(1, "typeName", "myType2OtherString", Type2.class)); // deserialize a json String json = "{\"i1\":{\"typeName\":\"myType1String\", \"fieldString\":\"foo\"}, \"i2\":{\"typeName\":\"myType2OtherString\", \"fieldDouble\": 84.7}}"; Cont res = deserializer.deserialize(json, Cont.class); // check the classes System.out.println(res.i1); System.out.println(res.i2); } } |