♨️onFailure: 통신실패 : CLEARTEXT communication to localhost not permitted by network security policy

http 요청을 막은 것. https 는 해당 없음

출처 : https://gun0912.tistory.com/80

android:usesCleartextTraffic="true"

<application
		...
        android:usesCleartextTraffic="true">

내 AVD 에서는 서버 주소를 (localhost ) 요청하는게 불가능함

따라서 ipv4 주소를 적어준뒤 :포트번호 해줌

그래도 이 오류가 떠서 찾아보고 일케 설정해주니 통신은 성공

♨️com.google.gson.JsonSyntaxException: 2021-10-12T09:10:23

타입이.. 타임스탬프라서 오브젝트로 변환하는 과정에 오류가 남

이제 이걸 timestamp 로 바꿔줄건데......험난한 여정...

@Override
public void onResponse(Call<CMRespDTO> call, Response<CMRespDTO> response) {
    Log.d(TAG, "onResponse: response : " + response.body().getData());
    ArrayList<Post> posts = (ArrayList)response.body().getData();

    for (int i=0; i<posts.size();i++){
        Gson gson = new Gson();
        String objToJson = gson.toJson(posts.get(i));
        //Log.d(TAG, "onResponse: objToJson: " + objToJson);
        Post post = gson.fromJson(objToJson, Post.class);
        Log.d(TAG, "onResponse: post : " + post);
    }

}
@Data
public class Post {
    private int id;
    private String title;
    private String content;
    private User user;
    **private Timestamp created;
    private Timestamp updated;**
}
@Override
    public void initData() {
        SharedPreferences pref = getSharedPreferences("myData", Context.MODE_PRIVATE);
        String authorization = pref.getString("token", "");
        //Log.d(TAG, "initData: authorization : " + authorization);
        Call<CMRespDTO> postList =  postController.findAll(authorization);
        postList.enqueue(new Callback<CMRespDTO>() {
            @Override
            public void onResponse(Call<CMRespDTO> call, Response<CMRespDTO> response) {
                Log.d(TAG, "onResponse: response : " + response.body().getData());
                ArrayList<Post> posts = (ArrayList)response.body().getData();
                List<Post> postList1 = new ArrayList<>();

                for (int i=0; i<posts.size();i++){
                    Gson gson = new Gson();
                    String objToJson = gson.toJson(posts.get(i));
                    JsonParser parser = new JsonParser();
                    JsonElement element = parser.parse(objToJson);

                    int id = element.getAsJsonObject().get("id").getAsInt();
                    String title = element.getAsJsonObject().get("title").getAsString();
                    String content = element.getAsJsonObject().get("content").getAsString();
                    //String userString = element.getAsJsonObject().get("user").getAsString();
                    //User user = gson.fromJson(userString, User.class);
                    Log.d(TAG, "onResponse: userString : " + userString);
//                    Timestamp created = Timestamp.valueOf(element.getAsJsonObject().get("created").getAsString());
//                    Timestamp updated = Timestamp.valueOf(element.getAsJsonObject().get("updated").getAsString());
//
//                    Post post = new Post(id, title, content, user, created, updated);

                    //postList1.add(post);
                }
//               postAdapter.addItems(postList1);
//                Log.d(TAG, "onResponse: postList1: " + postList1);

            }
Object responseData = response.body().getData();
Log.d(TAG, "onResponse: response : " + responseData);
Gson gson = new Gson();
String dataToJson = gson.toJson(responseData);
Log.d(TAG, "onResponse: responseData : " + dataToJson);