Coder Social home page Coder Social logo

Bump minimum Java to Java 8? about nanojson HOT 6 CLOSED

mmastrac avatar mmastrac commented on August 19, 2024
Bump minimum Java to Java 8?

from nanojson.

Comments (6)

mmastrac avatar mmastrac commented on August 19, 2024

That works for me. I think Java 8 is a reasonable target and Android was mainly the thing holding us back.

from nanojson.

dweiss avatar dweiss commented on August 19, 2024

Thanks! I'll go through the code in a spare minute and replace as many things as I can see.

from nanojson.

dweiss avatar dweiss commented on August 19, 2024

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.

mmastrac avatar mmastrac commented on August 19, 2024

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.

dweiss avatar dweiss commented on August 19, 2024

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.

mmastrac avatar mmastrac commented on August 19, 2024

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)

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.