jackson-js
jackson-js copied to clipboard
Metrics/Comparison
Would suggest adding metrics for comparison against other validation frameworks (Joi for example) to see how much overhead this adds vs. no validation (just json stringify/parse) or input validation including valid/invalid data in both shallow and deeper object structures. Using multiple simultaneous requests and measuring in requests per second over multiple seige runs on the same hardware.
Hi @tracker1, this is not a validation framework such as Joi.
jackson-js
is about serializing JavaScript objects/values into JSON string and deserializing JSON string into JavaScript objects/values with JavaScript decorators.
This library can be useful in more complex cases, for example when you want preserves type information (similar packages are: class-transformer and TypedJSON), hide some properties for certain HTTP endpoints or some other external services, have different JSON response for some external applications or manage different JSON data coming from other applications (for example you need to communicate with a Spring Boot application that uses different JSON Schema for the same model or with other applications made with python, PHP, etc...), manage cyclic references, manage other javascript native types such as Maps and Sets, etc.
For sure there will be overhead over the basic JSON.stringify
/parse
. That's because, before calling native JSON.stringify
/parse
method (both methods are called internally by jackson-js
), there is one step more to be called: the transform()
method. This method is used to detect and apply the jackson-js
decorators used on the JavaScript objects/values involved.
However, I could add Metrics/Comparison with basic JSON.stringify
/parse
(on both client and server side (Node.js)).
Does this framework validate the input at all? I'm not sure I see the value in preserving the Object type structure in JS all that much... Of course I usually take a more functional approach to JS.
If there's no validation, then what does this actually offer over JSON.stringify and JSON.parse?
This:
This library can be useful in more complex cases, for example when you want preserves type information (similar packages are: class-transformer and TypedJSON), hide some properties for certain HTTP endpoints or some other external services, have different JSON response for some external applications or manage different JSON data coming from other applications (for example you need to communicate with a Spring Boot application that uses different JSON Schema for the same model or with other applications made with python, PHP, etc...), manage cyclic references, manage other javascript native types such as Maps and Sets, etc.
with considering all jackson-js
JavaScript decorators and their options.
You can manipulate and manage, in a more simple way (using decorators and its options), your generated JSON and JSON data coming from other applications/services. You can customize your JSON content based on various contexts.
If you ever used the Java FasterXML/jackson annotations (probably on Spring Boot Applications), the use cases are much or less the same.
Instead, if you need to only parse and stringify basic objects/values, you can use simply JSON.parse
/stringify
methods.
There is a kind-of validation, for example using @JsonProperty({required: true})
, but it is not "The most powerful schema description language and data validator for JavaScript." as written on Joi website here.
So, to conclude, this library is about manipulating JSON (how JSON is generated/read), not validating it.
Java FasterXML/jackson annotation - http://tutorials.jenkov.com/java-json/jackson-annotations.html:
The Jackson JSON toolkit contains a set of Java annotations which you can use to influence how JSON is read into objects, or what JSON is generated from the objects.
Java tutorial and examples: https://springframework.guru/jackson-annotations-json/
Maybe still some performance comparison with https://github.com/marcj/marshal.ts? It don't have class polymorphism, but looks to be one of the fastest in this area
@maleet yes I will add performance comparison with it and others library. I'm already working on it but probably this library will not be the fastest one, also because it needs to do and check other things respect to, for example, marshal.ts. However it seems, on my first try to improve my library, that I can achieve pretty good performance. So, the focus of the next release is about improving performance.
@pichillilorenzo This library looks to be excellent (we've only just started with it) and should do wonders for those of us using Jackson to serialize JSON. Jackson is great at controlling the shape of the JSON it outputs and has allowed us to remove redundant fields in a number of places in our API. Unfortunately, that meant hand rolling our client side deserialization because of the limited capabilities of most similar libraries.
Thanks for the heavy lifting to get this bootstrapped 👍