jlbabilino / json Goto Github PK
View Code? Open in Web Editor NEWA simple Java library for JSON parsing, exporting, serialization, and deserialization. Supports inheritance and generics
License: GNU General Public License v3.0
A simple Java library for JSON parsing, exporting, serialization, and deserialization. Supports inheritance and generics
License: GNU General Public License v3.0
When a method in a super class is annotated with a serializing or deserializing annotation, and there is a sub implementation that does not have that annotation, the method marked will not be serialized/deserialized.
The default format option, JSONFormat.DEFAULT_FORMAT_CODE
, should be publicly visible.
Add a way to take a string and convert it back to an enum constant
Currently, abstract determiners only accept a JSONEntry
as the single parameter that a JSONSerializable
class can use to determine what type to deserialize. This should be extended. Here is an example where A
is the interface/abstract class, and B
and C
are classes that extend A
:
@DeserializedJSONDeterminer
public static TypeMarker<? extends A> determiner(JSONObject jsonObject) throws JSONDeserializerException {
if (!jsonObject.containsKey("type")) {
throw new JSONDeserializerException("Key \"type\" missing.");
}
JSONString typeJSONString = (JSONString) jsonObject.get("type");
String typeString = typeJSONString.getString();
switch (typeString) {
case "B":
return new TypeMarker<B>() {};
case "C":
return new TypeMarker<C>() {};
default:
throw new JSONDeserializerException("Unrecognized type string");
}
}
If this new feature were added, the code would simplify to:
@DeserializedJSONDeterminer
public static TypeMarker<? extends A> determiner(@DeserializedJSONObjectValue(key = "type") String typeString) throws JSONDeserializerException {
switch (typeString) {
case "B":
return new TypeMarker<B>() {};
case "C":
return new TypeMarker<C>() {};
default:
throw new JSONDeserializerException("Unrecognized type string");
}
}
This could be simplified even further if another feature were added:
@DeserializedJSONDeterminer
public static Class<? extends A> determiner(@DeserializedJSONObjectValue(key = "type") String typeString) throws JSONDeserializerException {
switch (typeString) {
case "B":
return B.class;
case "C":
return C.class;
default:
throw new JSONDeserializerException("Unrecognized type string");
}
}
Abstract determiners should work with both Class objects and TypeMarkers. Currently, only TypeMarker is supported.
All deserialization methods should be named deserialize()
, and since the signature of all four deserialization methods is unique, it won't matter.
This would be helpful to maintain encapsulation.
The SerializedJSONObjectValue
annotation should have an extra field called index
that by default is set to -1, but can be overwritten to set a custom one. -1 would indicate that the order does not matter. Numbered keys and null values would be used for the items in between indices if the user mistakenly missed an index in the sequence.
JSONParser
should be a final class, and the nullEntry()
method should be private
.
The deserialization annotations should have an extra field, required
, which, if true
, an exception will be thrown if the JSON entry is missing, and, if false
, a null
value will be passed in instead of causing an error.
This isn't super important but would be helpful
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.