2017-05-27 6 views
0

Ich verwende Retrofit 2, um einen Microservice aufzurufen, der bei einer PUT-Methode einen 200 und einen leeren Antworttext zurückgibt. Retrofit 2 scheint jedoch nicht in der Lage zu sein, dies zu handhaben und in der "enqueue" auf den Zweig onFailure geht
@Override public void onFailure (Anruf Anruf, Throwable t) {Retrofit2 OkHttp3 Response Body Null Fehler

Hier sind die Protokolle:

Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log 
INFORMATION: --> PUT http://127.0.0.1/test/ http/1.1 
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log 
INFORMATION: Content-Type: application/vnd.tipico.notification-v1+json 
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log 
INFORMATION: Content-Length: 87 
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log 
INFORMATION: 
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log 
INFORMATION: {"state":"ACTIVE","externalId":"abcd","loginName":"gsdfgsdf","updatedAt":1495531062000} 
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log 
INFORMATION: --> END PUT (87-byte body) 
Mai 27, 2017 3:26:50 PM okhttp3.internal.platform.Platform log 
INFORMATION: <-- 200 http://127.0.0.1/test/ (197ms) 
Mai 27, 2017 3:26:50 PM okhttp3.internal.platform.Platform log 
INFORMATION: X-Application-Context: customer-care-notification-service:49980 
Mai 27, 2017 3:26:50 PM okhttp3.internal.platform.Platform log 
INFORMATION: Content-Length: 0 
Mai 27, 2017 3:26:50 PM okhttp3.internal.platform.Platform log 
INFORMATION: Date: Sat, 27 May 2017 13:26:49 GMT 
Mai 27, 2017 3:26:50 PM okhttp3.internal.platform.Platform log 
INFORMATION: <-- END HTTP (0-byte body) 
15:26:50,030 ERROR com.test.app.Test - Failed CCNS call com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input 
at [Source: [email protected]; line: 1, column: 0] 

Wer weiß, was das verursacht? Da die Anfrage erfolgreich geliefert wurde (siehe oben).

+0

Das ist ziemlich seltsam hinzuzufügen. Ruft Ihr Aufruf irgendein Objekt zurück, das nachzurüsten versuchen könnte, zu deserialisieren? bei Anruf meine ich die Java-Schnittstelle – Fred

+0

Haben Sie eine Lösung gefunden? Ich stehe vor demselben Problem. Sieht so aus als ob das mit einigen Jackson Releases passiert. Welche Version verwendest du? – Pawan

+0

Hi, ja Sie müssen NullOnEmptyConverterFactory wie hier implementieren https://github.com/square/retrofit/issues/1554 – razvan

Antwort

0

habe ich eine Null-Handler-Konverter für dieses Problem:

public class NullOnEmptyConverterFactory extends Converter.Factory { 

    @Override 
    public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { 
     final Converter<ResponseBody, ?> delegate = retrofit.nextResponseBodyConverter(this, type, annotations); 
     return (Converter<ResponseBody, Object>) body -> { 
      if (body.contentLength() == 0) return null; 
      return delegate.convert(body); 
     }; 
    } 
} 

Sie müssen diesen Konverter vor Ihrer Gson Konverter

.addConverterFactory(new NullOnEmptyConverterFactory()) 
Verwandte Themen