Android 모바일 앱 클라이언트에서 AWS Lambda 함수 (서버리스 백엔드)를 호출하려고합니다. AWS 람다 함수는 POJO 객체의 ArrayList (JSON)를 반환합니다.Amazon Lambda에서 POJO의 ArrayList를 가져 오는 방법 (LinkedTreeMap 만 가져 오기)
문제는 안드로이드 클라이언트 AWS 람다 (JSON) DataBinder가 POJO의 내 ArrayList에 비 직렬화되지 않는다는 것입니다. LinkedTreeMap의 ArrayList를 얻습니다 (아래 onPostExecute() 코드 참조). com.amazonaws : AWS-안드로이드 SDK 코어 : 나는 안드로이드 AWS SDK를 사용하고 안드로이드 클라이언트 측에서
다음public void readSurveyList(String strUuid, int intLanguageID) {
// Create an instance of CognitoCachingCredentialsProvider
// You have to configure at least an AWS identity pool to get access to your lambda function
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
this.getApplicationContext(),
IDENTITY_POOL_ID,
Regions.EU_CENTRAL_1);
LambdaInvokerFactory factory = LambdaInvokerFactory.builder()
.context(this.getApplicationContext())
.region(Regions.EU_CENTRAL_1)
.credentialsProvider(credentialsProvider)
.build();
// Create the Lambda proxy object with default Json data binder.
myInterface = factory.build(MyInterface.class);
//create a request object (depends on your lambda function)
SurveyListRequest surveyListRequest = new SurveyListRequest(strUuid, intLanguageID);
// Lambda function in async task with definiton of
// request object (-> SurveyListRequest)
// response object (-> ArrayList<SurveyListItem>>)
new AsyncTask<SurveyListRequest, Void, ArrayList<SurveyListItem>>() {
@Override
protected ArrayList<SurveyListItem> doInBackground(SurveyListRequest... params) {
try {
return myInterface.ReadSurveyList(params[0]);
} catch (LambdaFunctionException lfe) {
Log.e("TAG", String.format("echo method failed: error [%s], details [%s].", lfe.getMessage(), lfe.getDetails()));
return null;
}
}
@Override
protected void onPostExecute(ArrayList<SurveyListItem> surveyList) {
// PROBLEM: here i get a ArrayList of LinkedTreeMap
}
}.execute(surveyListRequest);
}
코드입니다 : 여기에 2.6
몇 가지 코드 내 람다 함수의 인터페이스 :
public interface MyInterface {
@LambdaFunction
ArrayList<SurveyListItem> ReadSurveyList (SurveyListRequest surveyListRequest);
}
내 POJO 개체의 목록을 얻을 것으로 예상됩니다. Gson과 ArrayList 유형 및 TypeToken (예 : Gson TypeToken with dynamic ArrayList item type)을 기반으로 한 솔루션에 대해 많은 논의가있었습니다. 아마 같은 문제가 ...