0

[SOLVED] Fixed in Spring Framework:

restTemplate.getMessageConverters()
.add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));

I have cyrillic characters in response. I prefer using void method with RestContext because I use HTTP error codes for errors.

global class SalesOrder {
    global String name; //contains cyrillic letters
    ...
}

Works:

@HttpGet
global static SalesOrderWrapper getSalesOrder() {
    ...
    return salesOrder;    
}

Does not work (question marks instead of text):

@HttpGet
global static void getSalesOrder() {
    ...
    RestContext.response.responseBody = Blob.valueOf(JSON.serialize(salesOrder));
}

This does not help:

response.headers.put('Content-Type', 'application/json');
response.headers.put('charset', 'UTF-8');
1
  • How are you receiving your salesorder ? Commented May 31, 2016 at 1:00

2 Answers 2

5

Unfortunately I couldn't reproduce your bug, may be you've missed something, or it's 3rd party problem. Please find my example below:

global class SalesOrder {
    global String name; //contains cyrillic letters
    public SalesOrder(String name){
        this.name = name;
    }
}

@RestResource(urlMapping='/Account/*')
global with sharing class MyRestResource {
    @HttpGet
    global static void getSalesOrder() {
        SalesOrder salesOrder = new SalesOrder('Your name in Cyrillic here');
        RestResponse res = RestContext.response;
        res.responseBody = Blob.valueOf(JSON.serialize(salesOrder));
    }
}

And what I've got in Postman:

Cyrillic

1
  • Thanks, I see the issue is not in salesforce. On the other side there is Spring Framework and RestTemplate. I think issue is here. Commented May 31, 2016 at 7:25
2

I also tried with a basic example of Rest service and couldn't reproduce your issue. I am able to see the cyrillic characters in the workbench response. Can you please let me know how you are calling the Rest service?

@RestResource(urlMapping='/Account2/*')
global with sharing class MyRestResource {
    @HttpGet
    global static void doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
        //return result;
        RestContext.response.responseBody = Blob.valueOf(JSON.serialize(result.Name));
    }
}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .