JSON Library for Java with a focus on providing a clean DSL

Related tags

JSON skeson
Overview

Skeson

JSON Library for Java with a focus on providing a clean DSL

lit(21), address -> obj( street -> lit("Some where"), city -> lit("In some City"), state -> lit("In some State") ) )">
obj(
    name -> lit("Vaishnav"),
    age -> lit(21),
    address -> obj(
        street -> lit("Some where"),
        city -> lit("In some City"),
        state -> lit("In some State")
    )
)
{"name": "Vaishnav","age": 21,"address": {"street": "Some where","city": "In some City","state": "In some State"}}

Usage Example

IMPORTANT: Your application/library must be compiled with the -parameters command line argument

Type 1 (Preffered)

JsonAdapter
class Human {
  private final String name;
  private final int age;
  private final int height;

  Human(String name, int age, int height) {
      this.name = name;
      this.age = age;
      this.height = height;
  }

  public String getName() {
      return name;
  }

  public int getAge() {
      return age;
  }

  public int getHeight() {
      return height;
  }

  @Override
  public boolean equals(final Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      final Human human = (Human) o;
      return getAge() == human.getAge() && getHeight() == human.getHeight() && Objects.equals(getName(), human.getName());
  }

  @Override
  public int hashCode() {
      return Objects.hash(getName(), getAge(), getHeight());
  }
}

class HumanJsonAdapter implements JsonAdapter < Human > {

  @Override
  public JsonNode toJson(final Human object) {
      final String objectName = object.getName();
      final int objectAge = object.getAge();
      final int objectHeight = object.getHeight();
      return obj(
          name - > lit(objectName),
          age - > lit(objectAge),
          height - > lit(objectHeight)
      );
  }

  @Override
  public Human fromJson(final Consumer < JsonNode > readNode) {
      final LiteralReadingJsonNode < String > nameMatcher = matchString();
      final LiteralReadingJsonNode < Number > ageMatcher = matchNumber();
      final LiteralReadingJsonNode < Number > heightMatcher = matchNumber();
      readNode.accept(obj(
          name - > nameMatcher,
          age - > ageMatcher,
          height - > heightMatcher
      ));
      return new Human(nameMatcher.getValue(), ageMatcher.getValue().intValue(), heightMatcher.getValue().intValue());
  }
}

Type 2

Plain Json Read
final LiteralReadingJsonNode<String> nameMatcher = matchString();
final LiteralReadingJsonNode<Number> ageMatcher = matchNumber();
final BranchReadingJsonNode<ObjectJsonNode> addressMatcher = matchObject();
final JsonNode node = obj(
   name -> nameMatcher,
   age -> ageMatcher,
   address -> addressMatcher
);
node.match(jsonString);
System.out.printf("Name: %s\n", nameMatcher.getValue());
System.out.printf("Age: %s\n", ageMatcher.getValue());
System.out.printf("Address: %s\n", addressMatcher.getValue());
Plain Json Write
lit(21), address -> obj( street -> lit("Some where"), city -> lit("In some City"), state -> lit("In some State") ) ); System.out.println(node);">
final JsonNode node = obj(
   name -> lit("Vaishnav"),
   age -> lit(21),
   address -> obj(
       street -> lit("Some where"),
       city -> lit("In some City"),
       state -> lit("In some State")
   )
);
System.out.println(node);
You might also like...

A Java serialization/deserialization library to convert Java Objects into JSON and back

Gson Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to a

Jan 8, 2023

A universal types-preserving Java serialization library that can convert arbitrary Java Objects into JSON and back

A universal types-preserving Java serialization library that can convert arbitrary Java Objects into JSON and back, with a transparent support of any kind of self-references and with a full Java 9 compatibility.

Dec 30, 2021

A modern JSON library for Kotlin and Java.

Moshi Moshi is a modern JSON library for Android and Java. It makes it easy to parse JSON into Java objects: String json = ...; Moshi moshi = new Mos

Dec 31, 2022

Sawmill is a JSON transformation Java library

Sawmill is a JSON transformation Java library

Update: June 25, 2020 The 2.0 release of Sawmill introduces a breaking change to the GeoIpProcessor to comply with the updated license of the MaxMind

Jan 1, 2023

Genson a fast & modular Java Json library

Genson Genson is a complete json - java conversion library, providing full databinding, streaming and much more. Gensons main strengths? Easy to use

Jan 3, 2023

Lean JSON Library for Java, with a compact, elegant API.

mJson is an extremely lightweight Java JSON library with a very concise API. The source code is a single Java file. The license is Apache 2.0. Because

Dec 25, 2022

Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.

Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.

Elide Opinionated APIs for web & mobile applications. Read this in other languages: 中文. Table of Contents Background Documentation Install Usage Secur

Jan 3, 2023

High performance JVM JSON library

High performance JVM JSON library

DSL-JSON library Fastest JVM (Java/Android/Scala/Kotlin) JSON library with advanced compile-time databinding support. Compatible with DSL Platform. Ja

Jan 2, 2023

Screaming fast JSON parsing and serialization library for Android.

Screaming fast JSON parsing and serialization library for Android.

#LoganSquare The fastest JSON parsing and serializing library available for Android. Based on Jackson's streaming API, LoganSquare is able to consiste

Dec 18, 2022
Owner
Vaishnav Anil
Studying B.Tech in CSE w/ spez. in Gaming Tech.
Vaishnav Anil
Convert Java to JSON. Convert JSON to Java. Pretty print JSON. Java JSON serializer.

json-io Perfect Java serialization to and from JSON format (available on Maven Central). To include in your project: <dependency> <groupId>com.cedar

John DeRegnaucourt 303 Dec 30, 2022
A JSON Transmission Protocol and an ORM Library for automatically providing APIs and Docs.

?? 零代码、热更新、全自动 ORM 库,后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构。 ?? A JSON Transmission Protocol and an ORM Library for automatically providing APIs and Docs.

Tencent 14.4k Dec 31, 2022
JSON to JSON transformation library written in Java.

Jolt JSON to JSON transformation library written in Java where the "specification" for the transform is itself a JSON document. Useful For Transformin

Bazaarvoice 1.3k Dec 30, 2022
A simple java JSON deserializer that can convert a JSON into a java object in an easy way

JSavON A simple java JSON deserializer that can convert a JSON into a java object in an easy way. This library also provide a strong object convertion

null 0 Mar 18, 2022
Generate Java types from JSON or JSON Schema and annotates those types for data-binding with Jackson, Gson, etc

jsonschema2pojo jsonschema2pojo generates Java types from JSON Schema (or example JSON) and can annotate those types for data-binding with Jackson 2.x

Joe Littlejohn 5.9k Jan 5, 2023
Essential-json - JSON without fuss

Essential JSON Essential JSON Rationale Description Usage Inclusion in your project Parsing JSON Rendering JSON Building JSON Converting to JSON Refer

Claude Brisson 1 Nov 9, 2021
A 250 lines single-source-file hackable JSON deserializer for the JVM. Reinventing the JSON wheel.

JSON Wheel Have you ever written scripts in Java 11+ and needed to operate on some JSON string? Have you ever needed to extract just that one deeply-n

Roman Böhm 14 Jan 4, 2023
100% Java, Lambda Enabled, Lightweight Rules Engine with a Simple and Intuitive DSL

RuleBook » A Simple & Intuitive Rules Abstraction for Java 100% Java · Lambda Enabled · Simple, Intuitive DSL · Lightweight Why RuleBook? RuleBook rul

Delivered Technologies Labs 666 Dec 21, 2022
Java friendly DSL for defining TestFX tests

TestFX-DSL aims to bring DSL capabilities on top of TestFX. Inspired by Geb, this DSL enables a fluent interface design on top of the facilities exposed by TestFX.

Andres Almiray 5 Aug 21, 2019
Vert.x jOOQ DSL

jOOQ.x - Vertx jOOQ DSL jooqx leverages the power of typesafe SQL from jOOQ DSL and running on SQL connection in a reactive and non-blocking of SQL dr

zero88 18 Nov 16, 2022