Giter Site home page Giter Site logo

json's Introduction

json's People

Contributors

jlbabilino avatar

Stargazers

 avatar

Watchers

 avatar

json's Issues

Inherited method issue

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.

Abstract Determiners should accept regular deserialization parameters

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:

Original determiner

@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");
    }
}

Naming of Deserialization methods

All deserialization methods should be named deserialize(), and since the signature of all four deserialization methods is unique, it won't matter.

Add feature to set order of object items

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.

Add deserialization priority feature

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.

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.