Commons Json Utilities

Utilities for serialize and deserialize from JSON using Jackson

License

License

Categories

Categories

JSON Data
GroupId

GroupId

com.jarcasting
ArtifactId

ArtifactId

commons-json-utils
Last Version

Last Version

1.0.6
Release Date

Release Date

Type

Type

jar
Description

Description

Commons Json Utilities
Utilities for serialize and deserialize from JSON using Jackson
Project URL

Project URL

https://jarcasting.com/
Project Organization

Project Organization

JarCasting Java Libs Maven Directory
Source Code Management

Source Code Management

https://github.com/JarCasting/commons-json-utils

Download commons-json-utils

How to add to project

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

Dependencies

compile (8)

Group / Artifact Type Version
javax.json : javax.json-api jar 1.1
org.glassfish : javax.json jar 1.1
com.fasterxml.jackson.core : jackson-databind jar 2.11.3
com.fasterxml.jackson.module : jackson-module-parameter-names jar 2.11.3
com.fasterxml.jackson.datatype : jackson-datatype-jdk8 jar 2.11.3
com.fasterxml.jackson.datatype : jackson-datatype-jsr310 jar 2.11.3
com.fasterxml.jackson.datatype : jackson-datatype-jsr353 jar 2.11.3
org.apache.commons : commons-lang3 jar 3.5

test (1)

Group / Artifact Type Version
junit : junit jar 4.13

Project Modules

There are no modules declared in this project.

Commons Json Utils

Utilities for serialize and deserialize from JSON using Jackson

javadoc Maven Central

Maven

Functionality of this package is contained in Java package com.fasterxml.jackson.databind, and can be used using following Maven dependency:

<dependencies>
  ...
  <dependency>
    <groupId>com.jarcasting</groupId>
    <artifactId>commons-json-utils</artifactId>
    <version>1.0.4</version>
  </dependency>
  ...
</dependencies>

Depends on:

  • com.fasterxml.jackson.core : jackson-databind
  • com.fasterxml.jackson.module : jackson-module-parameter-names
  • com.fasterxml.jackson.datatype : jackson-datatype-jdk8
  • com.fasterxml.jackson.datatype : jackson-datatype-jsr310
  • com.fasterxml.jackson.datatype : jackson-datatype-jsr353
  • org.apache.commons : commons-lang3

Examples

JSON to POJO

  • json to Custom Object

        class MyClass {
            int a;
            int b;
        }
    
    
        MyClass result = 
            JsonUtils.fromJson(
                   "{\"a\":1,\"b\":2}", 
                   MyClass.class
            );
  • json to Enum

        enum MyEnum {
            A, B
        }
        enum MyEnum2 {
    
            A(87),
            B(89);
    
            int myField;
    
            MyEnum2(int myField) {
                this.myField=myField;
            }
    
        }
    
        public void jsonToEnum(){
            MyEnum result = JsonUtils.fromJson(
                    "\"A\"",
                    MyEnum.class
            );
            MyEnum2 result2 = JsonUtils.fromJson(
                    "\"B\"",
                    MyEnum2.class
            );
            Assert.assertEquals(JsonUtils.toJson2(result), "\"A\"");
            Assert.assertEquals(JsonUtils.toJson2(result2), "\"B\"");
        }
    
  • json to Generic Object

        static class MyGenericClass<T> {
            T value;
        }
        
        public void jsonToGenericObject() throws Exception {
    
            MyGenericClass<MySimpleClass> result = JsonUtils.fromJson(
                    "{\"value\":{\"a\":1,\"b\":2}}",
                    new TypeReference<MyGenericClass<MySimpleClass>>() { }
            );
    
            Assert.assertEquals(JsonUtils.toJson2(result), "{\"value\":{\"a\":1,\"b\":2}}");
    
        }
  • json to HashTable

        Hashtable<String, Integer> result =
                JsonUtils.fromJson("{\"a\":1,\"b\":2}",
                        new TypeReference<Hashtable<String, Integer>>(){}
                );
  • convert json to Key Value Pairs

        // TODO
    
  • json keyset

        Set<String> result = 
            JsonUtils.jsonKeySet("{\"a\":1,\"b\":2}");
  • json keys

        String[] result = 
            JsonUtils.jsonKeys("{\"a\":1,\"b\":2}");

Override Object.toString()

    @Override
    public String toString() {
        return JsonUtils.toJson(this);
    }

License

Licensed under the Apache License Version 2.0


JarCasting

com.jarcasting

JarCasting

Java Libraries Directory

Versions

Version
1.0.6
1.0.5
1.0.4
1.0.3
1.0.1