workday / autoparse-json Goto Github PK
View Code? Open in Web Editor NEWAutoparse JSON is a java library built specifically for Android that uses code generation to parse JSON into custom objects in your project.
License: MIT License
Autoparse JSON is a java library built specifically for Android that uses code generation to parse JSON into custom objects in your project.
License: MIT License
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.
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?
Java Writer is deprecated
See: https://github.com/square/javapoet#javawriter
Vulnerabilities were also detected
https://sbom.lift.sonatype.com/report/T1-a0368c8f29fdaa555824-242f3e11dbc9a2-1677540851-5ec98c71ea7e4f6fb18750a3996b0656
@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?
When the JSON provided from the server is an Array that contains nulls, for example:
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.
If a field is annotated like the following
@JsonValue(value = "myField", parser = MyParser.class)
Object theField;
then use the provided parser both when parsing and when updating the instance.
@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;
```
circle 1.0 will be EOL this month
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.