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

Wrong type in relationships section when using lookup by id and resource is a subtype. #861

Open
lgringo opened this issue Oct 5, 2022 · 0 comments

Comments

@lgringo
Copy link

lgringo commented Oct 5, 2022

Issue

Given a resource named main having one related resource named related of type a, and a have a sub-type b, and using @JsonApiRelation(lookup=AUTOMATICALLY_WHEN_NULL) and @JsonApiRelationId
When requesting main using include=related and repository implementation of main fills the id of related, but this id matches an instance of b (which extends a).
Result the type of related in relationships section is a, the type of related in included section is b
Expected Same type, ideally b into the 2 sections.

Example :

Resources

@JsonApiResource(type = "main")
public class MainResource {

	@JsonApiId
	private String id;

	@JsonApiRelationId
	private String relatedId

	@JsonApiRelation(lookUp = LookupIncludeBehavior.AUTOMATICALLY_WHEN_NULL)
	private A related;
}

@JsonApiResource(type = "a", subTypes = RelatedResourceB.class)
public class RelatedResourceA {
	@JsonApiId
	private String id;

	private String data;
}

@JsonApiResource(type = "b", resourcePath="a")
public class RelatedResourceB extends RelatedResourceA {

	private String otherData;
}

NB: Getters and setters are omitted for brevity.

Requests

NB: requests are written with httpie, for these examples, you just have to know that 'x==y' means add a request parameter x with value y.

  • http :8080/main/mainId include==related
{
    "data": {
        "id": "mainId",
        "links": " [...] "
        "relationships": {
            "related": {
                "data": {
                    "id": "mainId.B",
                    "type": "a"
                },
                "links": " [...] "
            }
        },
        "type": "main"
    },
    "included": [
        {
            "attributes": {
                "data": "Label from resource B",
                "otherData": "Other"
            },
            "id": "mainId.B",
            "links": " [...] ",
            "type": "b"
        }
    ],
    "links": " [...] "
}

data.relationships.related.data.type should match included[0].type

Remark

I know that having Crnk returning type b if included=related is not specified is not possible. But when included is present, types should match.

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

1 participant