Giter Site home page Giter Site logo

fluidsonic / fluid-json Goto Github PK

View Code? Open in Web Editor NEW
30.0 2.0 6.0 1.24 MB

A JSON library written in pure Kotlin

License: Apache License 2.0

Kotlin 100.00%
kotlin json json-library codec json-types decoding encoding parse annotations annotation-processing

fluid-json's People

Contributors

fluidsonic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fluid-json's Issues

Split up into multiple libraries

  • separate tests
  • properly define auto-closing of streams
  • clean up API
  • decide on final library naming
  • double-check Gradle project configurations
  • double-check test setup
  • double-check Travis CI setup
  • set up Maven Central publishing

Add stream-based parser and serializer (like MongoDB Java Driver)

  • Decide whether to treat map keys as values or whether to add special token type and readKey() method
  • Parse double directly without temporary string.
  • Add tests for character indexes in exception messages.
  • Add tests for keypaths in exception messages.
  • Should we wrap IOException, InterruptedException (all Exceptions?) in JSONException?
  • Serialize numbers without temporary string.
  • Improve performance by using Input/OutputStream directly.
  • Support Appendable.
  • Support Readable.
  • Support reading & writing Byte and Short.
  • Support reading & writing Char.
  • Allow peeking whether next number has decimal point or exponent in JSONReader.
  • Properly close readers & writers in tests.
  • Add overloads for readString and writeString which operate on CharArray and alike.
  • Add options (e.g. handling of unserializable values, max nesting, max number length, max string length)
  • Add dedicated tests for TextInput.

Polymorphism support

sealed class Shape
class Circle(val radius: Double) : Shape
class Rectangle(val width: Double) : Shape

There are 2 types of polymorphism:

  1. Polymorphism by field value, aka discriminator
    1.1 Discriminator embedded in object
[ { "type": "CIRCLE", "radius": 10.0 }, { "type": "RECTANGLE", "width": 20.0 } ]

1.2 Discriminator external

[ { "type": "CIRCLE", "data": { "radius": 10.0 } }, { "type": "RECTANGLE", "data": { "width": 20.0 } } ]
  1. Polymorphism by filed name, aka union, or anyOf from Swagger
[ { "radius": 10.0 }, { "width": 20.0 } ]

Because only Circle class has radius field, first object from list will be deserialized in Circle class.

Also should be possible to do nested deserialization(multi level).

Please add support for all this cases.

Add support for Validation

Usually on deserialization we want to collect all validation errors and return them in response to the client.
In order to catch all error the validation should be done before object creation.

If it will be done after object creation, in init block, than validation will be separated in 2 phases, first one will be validation regarding non-nullable field, because we cannot create objects if they have non-nullable properties.
The second one will be to do structural validation: min/max values, length, regexp pattern, etc.

Example
class Data(val name: String, val age: Int, val email: String)
when we send a json {"email": "[email protected]", "name": "A"} we should return a response where to indicate that age can not be null and name size must be greater than 2, at once to send all the errors.

Also, structural validation will be great to do based on annotations and not in init block, something like JSR 303.
This will be useful for documentation generation, it is far easier to generate based on annotations.

How I see the flow:

  1. Read annotations and generate validation rules. Can be done by 3rd party library. As result Map<Class, List>
  2. Parse json as a map
  3. Apply validation rules. Validation rules can be passed as parameter in configuration.
  4. Create object

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.