jsonapi-converter icon indicating copy to clipboard operation
jsonapi-converter copied to clipboard

include string does not work with nested models? "child.grandchild"

Open NullVoxPopuli opened this issue 7 years ago • 6 comments

Looking at the code for handling the include string:

    private SerializationSettings buildSerializationSettings(String includeString) {
        SerializationSettings.Builder settingsBuilder = new SerializationSettings.Builder();

        if (includeString != null) {
            String[] includes = includeString.split(",");

            for (String include: includes) {
                settingsBuilder.includeRelationship(include);
            }
        }

        SerializationSettings settings = settingsBuilder.build();

        return settings;
    }

the . character isn't dealt with -- it's important for for handling join relationships..

Let's say you have a user, organizations, and users_organizations -- for your user, you'd want to include 'users_organizations.organizations'. But the . causes neither of the relationships to be rendered.

NullVoxPopuli avatar Jan 12 '18 22:01 NullVoxPopuli

I'm also looking at using a include query parameter. Where is the code you mentioned? I cannot seem to find it... https://github.com/jasminb/jsonapi-converter/search?utf8=%E2%9C%93&q=includeString&type=

marceloverdijk avatar Jan 21 '18 21:01 marceloverdijk

@NullVoxPopuli I am not aware of nested relationship support in jsonapi specification.

jasminb avatar Jan 23 '18 12:01 jasminb

All libraries i've used (until i started using java libs) have supported nested includes.

From the specification:

The value of the include parameter MUST be a comma-separated (U+002C COMMA, “,”) list of relationship paths. A relationship path is a dot-separated (U+002E FULL-STOP, “.”) list of relationship names.

NullVoxPopuli avatar Jan 23 '18 14:01 NullVoxPopuli

Does jsonapi-converter support writing a JSONAPIDocument with defined includes per request / call to write method? I cannot seem to find that.

marceloverdijk avatar Jan 23 '18 15:01 marceloverdijk

Any plan to provide this functionality sometime soon? I also need it. and planning to hack a bit your code. I may share with you, if task is not already planned or in progress.

bmin avatar Mar 20 '18 20:03 bmin

I also need that fix, till then i have changed include string to be free from '.' . Also the solution should solve issue which arises when there is a include for same type object residing at different level in includes. unless we name both such relationship different we cannot serialize it.

manish-kevre avatar Feb 12 '19 12:02 manish-kevre