[Android Studio]Retrofit2 + GSON 에러 - 무한루프(?) 해결

|

Stackoverflow 
gson type
!!! FAILED BINDER TRANSACTION !!!

등이 에러가 났다. 3일 동안 앱 진행을 못했다. 결국 해냈다. 정확한 원인은 모르겠지만, 다음과 같이 하면된다.

이전엔 이렇게 Gson을 선언 했었다.

Gson gson = new GsonBuilder() .setLenient() .create();

여기에 excludeFieldsWithoutExposeAnnotation()를 추가해준다.

Gson gson = new GsonBuilder() .excludeFieldsWithoutExposeAnnotation() .setLenient() .create();

그리고 사용되는 파라미터들에 @Expose 어노테이션을 붙여준다.

public class SearchItem implements Serializable { @Expose String category; @Expose String subcategory; @Expose String country; @Expose String writer; @Expose String city; @Expose Date date; @Expose String keyword; }

일단, SearchItem은 이렇게 하지 않아도 되는데, UserItem에서 문제가 발생했기 때문에 다른 Item들도 바꿔줘야한다. UserItem에서 문제가 발생한 이유는 서버와 통신을 할 때 사용되지 않는 변수들이 있어서 그런 것 같다.


And