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

Unable to deserialise links relationship

Open aggarwalpulkit596 opened this issue 5 years ago • 11 comments

relationships: {run: {}, contents: {links: {related: "/api/v2/sections/5950/relationships/contents"}}}
contents: {links: {related: "/api/v2/sections/5950/relationships/contents"}}
links: {related: "/api/v2/sections/5950/relationships/contents"}
related: "/api/v2/sections/5950/relationships/contents"

above is my response,related link is not included in the so how to make an api call with the link obtained from related and serialise that response to the object

    @RelationshipLinks("contents")
    val contentsRelationshipLinks: Links?= null,
    @Relationship("contents",relType = RelType.RELATED)
    @JvmField
    var contents: ArrayList<LectureContent>? = null

i tried above method but it not working

aggarwalpulkit596 avatar May 06 '19 11:05 aggarwalpulkit596

@aggarwalpulkit596 Can you please provide more details, I'm not sure what you are asking.

jasminb avatar May 06 '19 11:05 jasminb

I want to hit the endpoint which I get in contentRelationshipLinks and then map that response to contents ArrayList object SerializationFeature.INCLUDE_RELATIONSHIP_ATTRIBUTES) This is not working as this section is not included in the same api call

aggarwalpulkit596 avatar May 06 '19 11:05 aggarwalpulkit596

@Type("section")
@JsonNaming(PropertyNamingStrategy.KebabCaseStrategy::class)
data class CourseSection(
    @JvmField
    val name: String,
    @JvmField
    var status: String,
    @JvmField
    var order: Int,
    @JvmField
    var createdAt: String,
    @JvmField
    var premium: Boolean,
    @JvmField
    var runId: String,
    @RelationshipLinks("contents")
    val contentsRelationshipLinks: Links?= null,
    @Relationship("contents",relType = RelType.RELATED)
    @JvmField
    var contents: ArrayList<LectureContent>? = null
) : BaseModel()

Above is my Section Model and

@Type("content")
@JsonNaming(PropertyNamingStrategy.KebabCaseStrategy::class)
data class LectureContent(
    @JvmField
    var section_content: SectionContent? = null,
    @Relationship("code-challenge")
    @JvmField
    var code_challenge: ContentCodeChallenge? = null,
    @Relationship("document")
    @JvmField
    var document: ContentDocumentType? = null,
    @Relationship("lecture")
    @JvmField
    var lecture: ContentLectureType? = null,
    @Relationship("progress")
    @JvmField
    var progress: ContentProgress? = null,
    @Relationship("video")
    @JvmField
    var video: ContentVideoType? = null,
    @Relationship("qna")
    @JvmField
    var qna: ContentQna? = null,
    @Relationship("csv")
    @JvmField
    var csv: ContentCsv? = null) : Contents()

and this is my lecture Content Model

aggarwalpulkit596 avatar May 06 '19 11:05 aggarwalpulkit596

If you want to automatically resolve relationship links, you can do so using the 'RelationshipResolver' mechanism.

Please see: https://github.com/jasminb/jsonapi-converter/blob/develop/src/test/java/com/github/jasminb/jsonapi/ResourceConverterTest.java#testLinkObjectsAndRelType

jasminb avatar May 06 '19 12:05 jasminb

@jasminb I tried using relationship resolved but that isn't working either

aggarwalpulkit596 avatar May 06 '19 12:05 aggarwalpulkit596

Basically, i want this endpoint to hit https://api-online.cb.lk/api/v2/sections/5950/relationships/contents but this endpoint is never requested

aggarwalpulkit596 avatar May 06 '19 12:05 aggarwalpulkit596

If you register a 'global' resolver, it should work.

Make sure to set resolve flag to true:

@RelationshipLinks("name", resolve = true)

jasminb avatar May 06 '19 12:05 jasminb

@jasminb you mean @Relationship("name", resolve = true) RelationshipLinks do not have a property resolve

aggarwalpulkit596 avatar May 06 '19 12:05 aggarwalpulkit596

@aggarwalpulkit596 yeah, copy-pasta issue...

jasminb avatar May 06 '19 12:05 jasminb

@jasminb Will try that and let you know if the issue persists

aggarwalpulkit596 avatar May 06 '19 12:05 aggarwalpulkit596

Screenshot 2019-05-06 at 7 49 57 PM As you can see contents are not mapped it is still null

aggarwalpulkit596 avatar May 06 '19 14:05 aggarwalpulkit596