jasminb / jsonapi-converter

JSONAPI-Converter is a Java/Android library that provides support for working with JSONAPI spec
Apache License 2.0
273 stars 81 forks source link

fixes a bug where ALLOW_UNKNOWN_INCLUSIONS wasn't checked before perf… #241

Closed Human closed 3 years ago

Human commented 4 years ago

…orming a more thorough check of 'included'

I believe commit 6e5f1d479ae1d27eceeaec81d1df7fdf57c0f66e introduced this regression. There's a new json resource and unit test that fails in 0.10 but passes in this branch. All other unit tests (including the ones added as part of 6e5f1d479ae1d27eceeaec81d1df7fdf57c0f66e) still pass.

jasminb commented 4 years ago

@Human thanks for PR, will take a look and merge/provide feedback.

jasminb commented 3 years ago

Hello @Human,

I've finally checked the PR.

Instead of making validation dependant on the ALLOW_UNKNOWN_INCLUSIONS, validation should be changed so it allows resource objects with only id and type attributes. Currently, validation also requires the attributes attribute which then causes the test to fail.

So, validation logic of included resources should be changed to correctly enforce the JSON spec: https://jsonapi.org/format/#document-resource-objects

Edit:

Following change to the validation logic should fix it:

    public static boolean isArrayOfResourceObjects(JsonNode dataNode) {
        if (dataNode != null && dataNode.isArray()) {
            for (JsonNode element : dataNode) {
                if (!isResourceObject(element) && !isResourceIdentifierObject(element)) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }