Giter VIP home page Giter VIP logo

autoparse-json's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

autoparse-json's Issues

Null Widget Received

The parser throws an exception when receiving a response that contains a null widget.
{ "widget":null }

The exception occurs in JsonParserUtils.java, line 541. Looks like we assume reader will have a nextString() if discriminationKeyName.equals(firstName), is true.

image

Is this the expected behavior? It might be more useful to ignore the null case, and move on to the next object.

For cases such as these, should it be the responsibility of the parser to gracefully deal with null cases, or the responsibility of the server to send valid objects?

Nulls in maps?

@ndtaylor I'm working on adding support for null values in maps and have come up with this test data.

"myStringMapWithSingleNullValue": { "key1": null }, "myStringMapWithNullValues": { "key1": null, "key2": "value2", "key3": "null" }, "myObjectMapWithNullValues": { "key1": { "myString": null }, "key2": { null }, "key3": { "myString": "value2" }, "key4": { "myString": "null" } }

"key2" in the object map isn't valid JSON. Is there a way to represent a null value in a case like this? A little background, we're trying to use JsonSelfValues to parse every field of a model, so we can determine how much we aren't parsing (and make some decisions based on that). We ran into nulls in an unparsed array which caused a crash, and I'm trying to proactively add support for nulls in maps (though we haven't seen them).

I don't think we should be making autoparse silently swallow malformed json like "key2", but would it be possible/reasonable for JsonSelfValues to not crash?

Problem with parsing array of nulls

When the JSON provided from the server is an Array that contains nulls, for example:
screen shot 2016-10-10 at 3 32 01 pm

this exception is thrown:

Caused by: java.lang.IllegalStateException: Could not convert value in array at "addressLines" to java.lang.Object from null.

This seems to happen because in the method parseFlatJsonArray, under the file JsonParserUtils.java, there's this code that throws an exception, since null is never an instance of Object.

if (typeClass.isInstance(nextValue)) {
                // This is safe since we are calling class.isInstance()
                @SuppressWarnings("unchecked")
                T toAdd = (T) nextValue;
                collection.add(toAdd);
            } else {
                throw new IllegalStateException(
                        String.format(Locale.US,
                                      "Could not convert value in array at \"%s\" to %s from %s.",
                                      key,
                                      typeClass.getCanonicalName(),
                                      getClassName(nextValue)));
            }

So Nathan, I wanted to ask your opinion of whether we should change this code to pass over the nulls and not throw an exception here, or if we need to leave it like this because it's expected to throw an exception if there are null values.

Autoparse generates private fields for public constructor params in Kotlin

@com.workday.autoparse.json.annotations.JsonObject(value = {"navigationItem", "navigationGroup"})
@kotlin.Metadata(mv = {1, 7, 1}, k = 1, d1 = {...})
public final class NavigationModel extends com.workday.workdroidapp.model.BaseModel {
    @org.jetbrains.annotations.NotNull
    @com.workday.autoparse.json.annotations.JsonValue(value = {"taskUrl"})
    private java.lang.String taskUrl;
    @org.jetbrains.annotations.NotNull
    @com.workday.autoparse.json.annotations.JsonValue(value = {"executeUrl"})
    private java.lang.String executeUrl;
    @org.jetbrains.annotations.NotNull
    @com.workday.autoparse.json.annotations.JsonValue(value = {"taskName"})
    private java.lang.String taskName;
    @org.jetbrains.annotations.NotNull
    @com.workday.autoparse.json.annotations.JsonValue(value = {"taskLabel"})
    private java.lang.String taskLabel;
    @org.jetbrains.annotations.NotNull
    @com.workday.autoparse.json.annotations.JsonValue(value = {"reportId"})
    private java.lang.String reportId;
    @com.workday.autoparse.json.annotations.JsonValue(value = {"currentTask"})
    private boolean currentTask;
    @org.jetbrains.annotations.NotNull
    @com.workday.autoparse.json.annotations.JsonValue(value = {"name"})
    private java.lang.String name;
    ```

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.