Comments (6)
That works for me. I think Java 8 is a reasonable target and Android was mainly the thing holding us back.
from nanojson.
Thanks! I'll go through the code in a spare minute and replace as many things as I can see.
from nanojson.
I filed a PR here. #47
I also noticed the current get(key, default) methods are not really possible to replace with getOrDefault because they currently return the default value if the existing value exists but is not of the right type. I don't know what the rationale for this was but it seems a bit trappy to me. Say, when you're parsing something and use getOrDefault then there is a possibility of passing an invalid input (with a key value of incorrect type) resulting in a silent replacement for the default, without any side-effects.
from nanojson.
Good point.
Say, when you're parsing something and use getOrDefault then there is a possibility of passing an invalid input (with a key value of incorrect type) resulting in a silent replacement for the default, without any side-effects.
The original design for this was that the parser should be able to traverse any provided JSON without throwing exceptions of any kind (although returning null in cases if no default was provided).
While I still like this guarantee for the get
methods, I think we could choose a few options to provide a non-swallowing API (roughly most to least favourable in my view):
- The caller could instruct the reader at construction time not to swallow improperly-typed values and throw a
ClassCastException
instead (my preference). If we leave the default to swallow those cast exceptions, that would be backwards-compatible. - Parallel getter methods could be provided
- Provide a callback where any potential class-cast exceptions could be passed in for handling and/or fixing up.
from nanojson.
Ok, fair enough. This didn't look like an oversight - that's why I asked. It can stay as it is, actually. I just found it mildly surprising because I typically prefer things to be the other way around -- break eagerly rather than be lenient. I've spent a great many hours debugging and trying to figure out what's going on when an important exception was quietly swallowed and ignored deep somewhere...
from nanojson.
Going to close this issue because nanojson now has a minimum required version of Java 8. Thanks for the help!
from nanojson.
Related Issues (20)
- nanojson could use a more active maintainer HOT 2
- Add 'Automatic-Module-Name' to MANIFEST.MF to support Java 9+ modules HOT 3
- Test failures in https://github.com/nst/JSONTestSuite HOT 3
- Modular nanojson compatible with jmod/jlink compilation HOT 1
- ArrayIndexOutOfBoundsException HOT 2
- Cut a 1.1 release HOT 1
- Make keys preserve ordering in JsonObject HOT 2
- Custom UTF8 stream decoding overhead/gain HOT 2
- Add a benchmark to https://github.com/fabienrenaud/java-json-benchmark HOT 3
- Add a reader mode with more exceptions HOT 2
- split got me throw a JsonWriterException: Unclosed JSON objects and/or arrays when closing writer HOT 2
- Writing of lazy numbers HOT 4
- [Feature] JsonWriter ByteArray mode HOT 1
- com.grack.nanojson.JsonLazyNumber should implement toString() like other java.lang.Number classes HOT 5
- Illegal Unicode Escaping HOT 1
- Stack overflow error caused by nanojson parsing of untrusted JSON String
- Expose JsonWriterBase#preValue(java.lang.String) HOT 1
- How to get length of an array
- non-finite numbers are written as invalid JSON
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanojson.