CyberSource / cybersource-rest-client-java

Java client library for the CyberSource REST API
Other
18 stars 42 forks source link

Response deserialization failure #143

Open ilsid opened 8 months ago

ilsid commented 8 months ago

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 commented 8 months ago

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();