aws-amplify / aws-sdk-android

AWS SDK for Android. For more information, see our web site:
https://docs.amplify.aws
Other
1.03k stars 549 forks source link

Encoding Problem while using Lambda #116

Closed nactusem closed 8 years ago

nactusem commented 8 years ago

I am using aws mobile sdk to save some data to dynamodb over lambda with Pojos. But before serialization process, json object and its attributes is normal as it should be

{ "address": { "S": "Ankara, Oğuzlar, 06520 Çankaya/Ankara, Türkiye" }, "creationDate": { "S": "Wed Mar 23 15:15:07 GMT+02:00 2016" }, "detail": { "S": "uç" }, "geohash": { "N": "1531222403039987611" }, "geoJson": { "S": "{\"type\":\"Point\",\"coordinates\":[32.8215751,39.901007]}" }, "jobHashKey": { "N": "153122" }, "kategori": { "S": "Tadilat" }, "photos": { "SS": [ "[\"file:///storage/emulated/0/WhatsApp/Media/WhatsApp%20Images/IMG-20160318-WA0000.jpg\"]" ] }, "place": { "M": { "lat": { "S": "32.8215751" }, "lng": { "S": "39.901007" } } }, "price": { "S": "255.0" } }

_After serialization it returns as below including corrupted Turkish characters. _{ "address": { "S": "Ankara, O��uzlar, 06520 ��ankaya/Ankara, T��rkiye" }, "creationDate": { "S": "Wed Mar 23 15:15:07 GMT+02:00 2016" }, "detail": { "S": "u��" }, "geohash": { "N": "1531222403039987611" }, "geoJson": { "S": "{\"type\":\"Point\",\"coordinates\":[32.8215751,39.901007]}" }, "jobHashKey": { "N": "153122" }, "kategori": { "S": "Tadilat" }, "photos": { "SS": [ "[\"file:///storage/emulated/0/WhatsApp/Media/WhatsApp%20Images/IMG-20160318-WA0000.jpg\"]" ] }, "place": { "M": { "lat": { "S": "32.8215751" }, "lng": { "S": "39.901007" } } }, "price": { "S": "255.0" }, "title": { "S": "��" } }

Couldnt find a solution for this, May I request your assistance, or is it a bug? Thank you for your time.

fosterzhang commented 8 years ago

@felusdomesticus Thanks for reporting. I am looking into this.

fosterzhang commented 8 years ago

Are you using the latest version v2.2.13? A few internalization issues were addressed in v2.2.13.

nactusem commented 8 years ago

Yes, I am using that version, I addressed another bug fixed in that version https://github.com/aws/aws-sdk-android/issues/96

fosterzhang commented 8 years ago

Would you please try this in Lambda console? I suspect Lambda doesn't return correct content.

nactusem commented 8 years ago

I tried this in console and works perfect.

fosterzhang commented 8 years ago

How to reproduce it? I have a simple echo function set up in Lambda. I set default locale to Turkish. I can see the correct content.

Lambda function

console.log('Loading event');

exports.handler = function(event, context) {
    console.log("Received event");
    console.log(event);
    context.done(null, event);
};

Java interface

public interface MyInterface {
    @LambdaFunction
    NameInfo echo(NameInfo nameInfo);
}

public class NameInfo {
    public String firstName;
    public String lastName;
    public NameInfo(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }
}

    Locale.setDefault(new Locale("tr", "TR"));
    NameInfo nameInfo = new NameInfo("Big", "Oğuzlar");
    NameInfo result = myInterface.echo(nameInfo);
    System.out.println(result.lastName);
nactusem commented 8 years ago

I tried this case and with node js backend i can see the correct content. But with java backend lambda logs and android side content is wrong. On the other hand if i try with lambda console content is right. Here is my sample code.

Lambda function

public NameInfo javaEncodingTest(NameInfo nameInfo, Context context){ context.getLogger().log(nameInfo.toString()); return nameInfo; }

Java interface with Android

` public interface MyInterface { @LambdaFunction NameInfo javaEncodingTest(NameInfo nameInfo); }

public class NameInfo { public String firstName; public String lastName;

public String getFirstName() { return firstName; }

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

}

NameInfo nameInfo = new NameInfo(); nameInfo.setFirstName("türkçe"); nameInfo.setLastName("türkçe"); NameInfo result = myInterface.javaEncodingTest(nameInfo); System.out.println(result.lastName); `

Lambda console log is START RequestId: da8ea4d1-f1c9-11e5-96ec-057690f11223 Version: $LATEST t��rk��e t��rk�� END RequestId: da8ea4d1-f1c9-11e5-96ec-057690f11223 REPORT RequestId: da8ea4d1-f1c9-11e5-96ec-057690f11223 Duration: 0.73 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 37 MB

fosterzhang commented 8 years ago

Hmm, interesting problem. I used Charles to sniff http traffic. I notice the SDK does sent correct content to Lambda. But for some reason, Lambda doesn't handle it correctly and return incorrect content. I'll loop Lambda team in for investigation.

nactusem commented 8 years ago

Thank you for your response, how can I follow this issue? @fosterzhang

nactusem commented 8 years ago

Is there any progress @fosterzhang ?

fosterzhang commented 8 years ago

@felusdomesticus I know what's causing it, but I don't know why. I forwarded this issue to Lambda team.

nactusem commented 8 years ago

Can you please change this to a bug? We are all awaiting this to continue properly our development and test @fosterzhang , thanks

fosterzhang commented 8 years ago

@felusdomesticus Technically this isn't a bug in the SDK. I handed it over to Lambda team and they are working on it. Thank you for your patience.

ngoclinh49 commented 8 years ago

hello, this issue are solve?

fosterzhang commented 8 years ago

@ngoclinh49 This bug has been taken care of by the Lambda team. They will roll out the fix ASAP.

fcabi commented 8 years ago

@fosterzhang Is there any progress? This makes lambda unusable. Please fix this ASAP. Thanks.

fosterzhang commented 8 years ago

@fcabi @ngoclinh49 This is beyond the SDK. I've pinged Lambda team to have it fixed ASAP.

fosterzhang commented 8 years ago

@ngoclinh49 @fcabi @felusdomesticus FYI: this is fixed in a recent Lambda service update.

saaksshi commented 5 years ago

This issue again coming when I'm sending Arabic response in lambda

saaksshi commented 5 years ago

It's works fine in Lex console testing but in swift mobile app Arabic gets truncated.

palpatim commented 5 years ago

@saaksshi Please open a new issue with complete details rather than extending a very old issue. The "Bug" template will have a list of information that will help developers troubleshoot the issue.