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

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

Open NullVoxPopuli opened 6 years ago

NullVoxPopuli commented 6 years ago

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.

marceloverdijk commented 6 years ago

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=

jasminb commented 6 years ago

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

NullVoxPopuli commented 6 years ago

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.

marceloverdijk commented 6 years ago

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

bmin commented 6 years ago

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.

manish-kevre commented 5 years ago

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.