Coder Social home page Coder Social logo

Comments (3)

DannyvdSluijs avatar DannyvdSluijs commented on June 15, 2024 1

@CReimer I think the rough outline of steps would be:

  • Create a new middleware (with some meaningfull name)
  • Define the logic you need (the $json will hold the data and the $propertyMap contains the results of earlier executed middleware such a TypedProperties and DocBlockAnnotations. Using something like array_keys($propertyMap->getIterator()->getArrayCopy()) you can get the names of the properties and use them in an array_diff against the keys of the Json to find the missing properties from the Json
  • Add a specific Exception that can hold the data that is required by consumers of the package
  • You can then add some feature tests that confirm the expected results.
  • Optionally you can extent the JsonMapperBuilder with some method to add the middleware.

No worries if you can't figure it out. I can help if needed Im just rather occupied ATM. You could also work in a TDD approach and just provide the testcase and I can take it from there when I find the time.

from jsonmapper.

DannyvdSluijs avatar DannyvdSluijs commented on June 15, 2024

Hi @CReimer

Thanks for the report and also apologies for the later reply but due to my holidays and moving into a new house my time was consumed with other items.

I think it would not be core functionality of JsonMapper but something which can easily be done using a new middleware that compares the keys of the given JSON and take the non-nullable properties of the property map and see if any keys are missing. The you can either throw the exception or keep track of the exceptions (to avoid running into issues with multiple mappings) and use the FinalCallback to due something with the collected exceptions.

I do see the added value in this but am rather curious how you would use this in production systems where (external) misinformed data would lead to an exception?

Also would you be willing to make a pull request for this?

from jsonmapper.

CReimer avatar CReimer commented on June 15, 2024

I do see the added value in this but am rather curious how you would use this in production systems where (external) misinformed data would lead to an exception?

That's exactly my point. My goal is to terminate the request with an HTTP 400 Bad request or something else in the 4xx range.

Also would you be willing to make a pull request for this?

Yeah, of course. But can you give me some pointers first? Where should I start?

from jsonmapper.

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.