Crell / Serde

Robust Serde (serialization/deserialization) library for PHP 8.
Other
299 stars 14 forks source link

Allow fields to require a value be provided on deserialiation. #22

Closed Crell closed 1 year ago

Crell commented 1 year ago

Description

Adds a new boolean to the Field attribute to require the property. Also a new boolean field to the class to require any property that doesn't specify otherwise.

Given how easy it is to set on a class level, I am going to leave all the defaults at false. It's messing with a lot of other tests otherwise.

I've also decided that if a field is nullable, that means nothing. If you want a default value of null in case of a missing value... set a default value. That support already exists.

Motivation and context

Fixes #7 Fixes #14

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our continuous integration server to make sure your tests and code style pass.

Crell commented 1 year ago

@repli2dev This work for your use case?

repli2dev commented 1 year ago

@Crell it seems it should, yet with a bit more writing, probably acceptable.