Skip to content

Commit payload deserialization produces an exception #8

Open
@csanadtelbisz

Description

@csanadtelbisz

SysML v2 API Java client version: 2021-09 (commit: Merge branch 'release/2021-09' on Oct 15, 2021)

Steps to reproduce:

  • Using the api client, create a project and a commit with some SysMLv2 element (e.g. with type ActionDefinition).
  • Send a request to get the created commit (use getCommitByProjectAndId method with the id of the created project and commit).

The following simple project reproduces the problem: api-client-bug-report.zip. Essential part:

val projectApi = ProjectApi(defaultClient)
val commitApi = CommitApi(defaultClient)
// ...
val project = projectApi.postProject(Project().apply { name = "demo project" })
val commit = commitApi.postCommitByProject(project.atId, Commit().apply {
    change = listOf(DataVersion().apply {
        val id = UUID.randomUUID()
        identity = DataIdentity().atId(id)
        payload = Data().apply {
            put("@id", id.toString())
            put("@type", "ActionDefinition")
            put("empty", Random.nextBoolean())
        }
    })
}, null)
commitApi.getCommitByProjectAndId(project.atId, commit.atId) // Exception: cannot determine model class of name: <ActionDefinition>

Expected output: the result of the getCommitByProjectAndId request is a Commit object with the appropriate content.

Actual output: an exception: IllegalArgumentException: cannot determine model class of name: <ActionDefinition>

Additional info: the stacktrace reveals (see below) that the exception occurs in the getClassByDiscriminator method of JSON.java when trying to deserialize the response (more specifically when the payload of the commit change is deserialized). The source of the problem is that the @type property of the payload is used to determine the class for the result of the deserialization. The type (e.g. ActionDefinition) is searched in a hash map which only contains the key Data in our case (see the creation of the hash map).

Exception in thread "main" java.lang.IllegalArgumentException: cannot determine model class of name: <ActionDefinition>
	at org.omg.sysml.JSON.getClassByDiscriminator(JSON.java:96)
	at org.omg.sysml.JSON.access$100(JSON.java:44)
	at org.omg.sysml.JSON$1.getClassForElement(JSON.java:69)
	at io.gsonfire.gson.TypeSelectorTypeAdapterFactory$TypeSelectorTypeAdapter.read(TypeSelectorTypeAdapterFactory.java:65)
	at io.gsonfire.gson.NullableTypeAdapter.read(NullableTypeAdapter.java:36)
	at io.gsonfire.gson.HooksTypeAdapter.deserialize(HooksTypeAdapter.java:86)
	at io.gsonfire.gson.HooksTypeAdapter.read(HooksTypeAdapter.java:54)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
	at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
	at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
	at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
	at com.google.gson.Gson.fromJson(Gson.java:932)
	at com.google.gson.Gson.fromJson(Gson.java:897)
	at com.google.gson.Gson.fromJson(Gson.java:846)
	at org.omg.sysml.JSON.deserialize(JSON.java:163)
	at org.omg.sysml.ApiClient.deserialize(ApiClient.java:775)
	at org.omg.sysml.ApiClient.handleResponse(ApiClient.java:978)
	at org.omg.sysml.ApiClient.execute(ApiClient.java:905)
	at org.omg.sysml.api.CommitApi.getCommitByProjectAndIdWithHttpInfo(CommitApi.java:168)
	at org.omg.sysml.api.CommitApi.getCommitByProjectAndId(CommitApi.java:144)
	at MainKt.main(Main.kt:43)
	at MainKt.main(Main.kt)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions