Skip to content

Can you add one JSON_FORCE_OBJECT property in ApiProblemResponse jsonFlags  #1

@weierophinney

Description

@weierophinney

In your current code ApiProblemResponse class have this constructor

public function __construct(ApiProblem $apiProblem)
    {
        $this->apiProblem = $apiProblem;
        $this->setCustomStatusCode($apiProblem->status);
        $this->setReasonPhrase($apiProblem->title);
        $this->jsonFlags = JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR;
    }

Could you please add one more property in jsonFlags JSON_FORCE_OBJECT

Like this

public function __construct(ApiProblem $apiProblem)
    {
        $this->apiProblem = $apiProblem;
        $this->setCustomStatusCode($apiProblem->status);
        $this->setReasonPhrase($apiProblem->title);
        $this->jsonFlags = JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_FORCE_OBJECT;
    }

This will give api response to send non associated arrays keys for example during validation message generation, when keys are number and not string

like this

array(
3 =>'message1',
5 =>'message2',
7 =>'message3',
)

Originally posted by @developer-devPHP at zfcampus/zf-api-problem#56

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions