Git Product home page Git Product logo

Comments (4)

opinali avatar opinali commented on May 8, 2024

I agree this would be a nice improvement... normally, the read method should return null for empty string, because an empty string is not a valid representation of any JSON object (an "empty" JSON object must contain at least {}). But it's nasty to make the reader methods @Nullable only for this special case. I think we can just return BidRequest.getDefaultInstance(), which also doesn't require special casing in the caller. (The default instance is a fixed object, so you can detect if that was the returned object if you care.)

from openrtb.

Spikhalskiy avatar Spikhalskiy commented on May 8, 2024

an empty string is not a valida representation of any JSON object

Sure, that is why we definitely shouldn't return BidRequest with default content here

But it's nasty to make the reader methods @nullable only for this special case.

I'm not sure. Reader return "nothing" only if there is "nothing" in input and only in this case. So, this case is enough for Nullable from my perspective.
I don't like "defaultInstance" solution, because it's

  1. looks like a hack and magic object
  2. "{}" is default object ideologically, so we need getEmptyInstance and it's definitely looks like a hack because empty object is null

Accuracy to Nullable - this is why I suggest to make it as feature that user can enable. In default behavior we never return null and throw and exception (but maybe rework to throw some specific like EmptyInputException), but if user explicitly enable parsing empty input as null - we will return null.

from openrtb.

opinali avatar opinali commented on May 8, 2024

Some good points... returning the default object is clean in the theory because the Protobuf library documents that this thing is a singleton; still, I agree it's not a popular and obvious API design.

Now, an empty string is not a valid JSON input, so the exception you get today is the perfect behavior for strict parsing. Unfortunately there's no good way to detect the cause of Jackson's exceptions, other than matching the message strings, otherwise I would dismiss this as WAI. We already have a "strict" option in the API, so that's a perfect candidate for the desired feature: do setStrict(false), then the read methods will mask this special case and return null. I'm still not friendly to the idea of making the return types @Nullable for the sake of a corner case (if you have some exchange/platform sending you empty-string requests or responses they are doing it wrong...), but I suppose it's not a big sin to return null without declaring @Nullable if the user has set a strict=false option; that opens the Pandora box of "I know what I'm doing" so it looks like a good tradeoff.

from openrtb.

opinali avatar opinali commented on May 8, 2024

(0.9.6 improved this; closing bug.)

from openrtb.

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.