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

Response deserialization failure #143

Open
ilsid opened this issue Jan 31, 2024 · 1 comment
Open

Response deserialization failure #143

ilsid opened this issue Jan 31, 2024 · 1 comment

Comments

@ilsid
Copy link

ilsid commented Jan 31, 2024

Hello team,

Looks like the Content-Type header in a server response has been changed recently and is not supported by Java client
I'm getting now the following error when invoking Api.PaymentsApi.createPayment(CreatePaymentRequest). It used to work fine before.

Content type "application/hal+json,application/hal+json;charset=utf-8" is not supported for type: class Model.PtsV2PaymentsPost201Response

Please see
https://github.com/CyberSource/cybersource-rest-client-java/blob/master/src/main/java/Invokers/ApiClient.java#L1064
https://github.com/CyberSource/cybersource-rest-client-java/blob/master/src/main/java/Invokers/ApiClient.java#L953

Tried versions 0.0.58 and 0.0.60

Thanks

@ilsid
Copy link
Author

ilsid commented Feb 1, 2024

For a quick problem resolution, I made a small patch in my code using Javassist library

ClassPool classPool = ClassPool.getDefault();
CtClass ctClass = classPool.get("Invokers.ApiClient");
CtMethod ctMethod = ctClass.getDeclaredMethod("isJsonMime");

// This is a small change for the jsonMime regexp to accept "application/hal+json,application/hal+json;charset=utf-8"
// Content-Type response header. Actually, a server should return
// "application/hal+json;charset=utf-8" header value (no duplication). In this case, no fixes are needed.
ctMethod.setBody("{ " +
                    "String jsonMime = \"(?i)^(application/json|[^;/ \\t]+/[^;/ \\t]+[+]json)[ \\t]*(.*)?$\"; " +
                    "return $1 != null && ($1.matches(jsonMime) || $1.equalsIgnoreCase(\"application/json-patch+json\")); " +
                 "}");

ctClass.toClass();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant