Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema doesn't respect Object #10

Open
djdance opened this issue Mar 23, 2023 · 4 comments
Open

Schema doesn't respect Object #10

djdance opened this issue Mar 23, 2023 · 4 comments

Comments

@djdance
Copy link

djdance commented Mar 23, 2023

We are trying to work with schemas.
It appears that it sends any king of object, regardless of schema set.
For example, it will send your initial Person Object from the example without any errors.
The only thing it checks is schema itself, it must be valid (that's okay).

Is there any option to validate an object before send?

thanks

@ikilobyte
Copy link
Owner

@djdance

Yes, schemas can send any object to pulsar without validating the object options, but it must meet this one requirement, the object must be able to json_encode, however json_encode will only extract public properties, so as long as the object can successfully json_encode it will be sent successfully, the same goes for the consumer, when it receives When the json data is received, it will be converted to the corresponding object, and there is no need to manually convert it to an object, which saves us a lot of conversion work

example

class Person
{
    public $id;
    public $name;
    public $age;

    protected $test = 'ignore';
    // ...
}

$person = new Person();
$person->id = 1;
$person->name = 'Tony';
$person->age = 1;

echo json_encode($person);

// output:{"id":1,"name":"Tony","age":1}

$producer->send($person);   // The actual message sent is `{"id":1,"name":"Tony ","age":1}`

@djdance
Copy link
Author

djdance commented Mar 23, 2023

got it.
Would you plan to add some kind of validation to Object sending?
as in appropriate Java library (they say)

@ikilobyte
Copy link
Owner

I don't know what verification there is in the java library, can you tell me in detail?

@djdance
Copy link
Author

djdance commented Mar 23, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants