Code Monkey home page Code Monkey logo

sjson's Introduction

Build

SJson

SJson is a lightweight tailer made json parser for server side workloads. It tries to get optimized memory and performance with below goals.

  1. Optimized for Serialization, Deserialization and validation.
  2. Represent Json in native java format.
  3. No external dependencies
  4. Trust the validity of json documents. It is just enough to say invalid, reasoning is optional
  5. Utilize latest java features

Note: This is not general purpose parser. This is specifically written for REST API use cases.

  1. Service to Service Communications in microservices
  2. Client SDK such as Elastic REST Client.

Usage

Include below in your pom.xml

<dependency>
   <groupId>com.techatpark.sjson</groupId>
   <artifactId>json-parser</artifactId>
   <version>1.0.0</version>
<dependency>   

Below is the code to read JSON as Java Object

   Json json = new Json();
   Object obj = json.read(new StringReader("{ \"abc\" : \"def\" }"));

Development

Below VM Options should be added for JVM. This is required to calculate the size of the objects

-javaagent:<<PATH_TO_JAR>>/jamm-0.4.1.jar --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED

How it works

SJson was part of the tech talk series at Bangalore Opensource Java User Group. This will give an idea behind this work.

  1. Setup : https://www.youtube.com/watch?v=q_1H8ZJceA8
  2. Optimization: https://www.youtube.com/watch?v=XMRaLCRfvlQ
  3. Collection: https://www.youtube.com/watch?v=tMgy5PxPFQ4

sjson's People

Contributors

amir-suhel avatar developeranand17 avatar dhamu-ram avatar jaydeosahu avatar manikantayarramsetti1 avatar mohit-sahu avatar rmhari avatar sathishk avatar sen091 avatar toshi-singh avatar vijaywhat avatar vish7777 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sjson's Issues

Test Isolation

s of now both valid and invalid test cases are together. this should be separated as they have senate flow

Invalid Parsing with Objects

@Test
    void testJSon() throws IOException {
        String jsonText = """
                {
                  "trueKey": true,
                  "falseKey": false,
                  "trueStrKey": "true",
                  "falseStrKey": "false",
                  "stringKey": "hello world!",
                  "intKey": 42,
                  "intStrKey": "43",
                  "longKey": 1234567890123456789,
                  "longStrKey": "987654321098765432",
                  "doubleKey": -23.45e7,
                  "doubleStrKey": "00001.000",
                  "BigDecimalStrKey": "19007199254740993.35481234487103587486413587843213584",
                  "negZeroKey": -0.0,
                  "negZeroStrKey": "-0.0",
                  "arrayKey": [0, 1, 2],
                  "objectKey": {
                    "myKey": "myVal"
                  }
                }
                """;
        Map<String,Object> ourJsonObject = (Map<String, Object>) new Json().read(new StringReader(jsonText));
        JsonNode jacksonJsonNode = new ObjectMapper().readTree(jsonText);
        String reversedJsonText = jackson.writeValueAsString(ourJsonObject);

        Assertions.assertEquals(jacksonJsonNode,
                jackson.readTree(new StringReader(reversedJsonText)),
                "Reverse JSON Failed");
    }

.mvn dir should not be commited in repo

Reasons are

  1. This is a generated directory, none should touch nor version control
  2. even mvnw.cmd mvnw should not be changed, let dev know to use the command ./mvnw -N wrapper:wrapper -Dmaven=3.8.7 to upgrade maven from command line
  3. I love developers using a different versions of java, mvn etc to report compliance issues early on, rather than enforcing just xyz version of java etc..
  4. If strictly required java version and mvn version should be captured in pom.xml

Divide By Zero Bug-Windows

Getting "java.lang.ArithmeticException: / by zero" bug while running the performance test testcase in windows.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.