The place where ORY's SDKs are being auto-generated
Apache License 2.0
139
stars
86
forks
source link
kratos-client-java: IllegalArgumentException: Expected the field `oauth2_login_challenge` to be a primitive type in the JSON string but got `null` #241
IllegalArgumentException: Expected the field oauth2_login_challenge to be a primitive type in the JSON string but got null
Reproducing the bug
val frontendApi = FrontendApi(ApiClient()).apply {
customBaseUrl = "https://playground.projects.oryapis.com"
}
frontendApi.createNativeRegistrationFlow()
Relevant log output
Caused by: java.lang.IllegalArgumentException: Expected the field `oauth2_login_challenge` to be a primitive type in the JSON string but got `null`
at sh.ory.kratos.model.RegistrationFlow.validateJsonObject(RegistrationFlow.java:458)
at sh.ory.kratos.model.RegistrationFlow$CustomTypeAdapterFactory$1.read(RegistrationFlow.java:500)
at sh.ory.kratos.model.RegistrationFlow$CustomTypeAdapterFactory$1.read(RegistrationFlow.java:490)
at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)
at com.google.gson.Gson.fromJson(Gson.java:991)
at com.google.gson.Gson.fromJson(Gson.java:956)
at com.google.gson.Gson.fromJson(Gson.java:905)
at sh.ory.kratos.JSON.deserialize(JSON.java:334)
at sh.ory.kratos.ApiClient.deserialize(ApiClient.java:847)
at sh.ory.kratos.ApiClient.handleResponse(ApiClient.java:1055)
at sh.ory.kratos.ApiClient.execute(ApiClient.java:979)
at sh.ory.kratos.api.FrontendApi.createNativeRegistrationFlowWithHttpInfo(FrontendApi.java:1335)
at sh.ory.kratos.api.FrontendApi.createNativeRegistrationFlow(FrontendApi.java:1315)
if (jsonObj.get("oauth2_login_challenge") != null && !jsonObj.get("oauth2_login_challenge").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `oauth2_login_challenge` to be a primitive type in the JSON string but got `%s`", jsonObj.get("oauth2_login_challenge").toString()));
}
I haven't worked with gson for a long time, but I see that jsonObj.get returns a JsonElement, which has this public check
/**
* provides check for verifying if this element represents a null value or not.
*/
public boolean isJsonNull() {
return this instanceof JsonNull;
}
Preflight checklist
Describe the bug
I can't start a native registration flow using https://github.com/ory/kratos-client-java
Reproducing the bug
Relevant log output
On the server side
Relevant configuration
Version
0.11.0
On which operating system are you observing this issue?
macOS
In which environment are you deploying?
Docker Compose
Additional Context
The response from the server is
The relevant code in
RegistrationFlow.java
isI haven't worked with gson for a long time, but I see that
jsonObj.get
returns aJsonElement
, which has this public checkDebugging the
JsonObject
, this is themembers
MapThus, the generated call should either check
isJsonNull()
and accept a NPE if member is not present, or do both!= null && !.isJsonNull()
This should be done for all java models, I am afraid.
In the past, I used static functions to not having to write so much code. Something like