Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why do I get different result when use different ways to serialize emoji char. #2123

Closed
ghost opened this issue Aug 26, 2018 · 1 comment
Closed

Comments

@ghost
Copy link

ghost commented Aug 26, 2018

0. at first

  • springboot version
    1.5.12
  • jackson version
    2.8.11

1.code

import javax.annotation.Resource;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    @RequestMapping(value = "/model")
    public Model model() {
        Model model = new Model();
        model.setId(1);
        model.setEmoji("\uD83D\uDE33");
        return model;
    }

    @RequestMapping(value = "/string")
    public String modelString() {
        Model model = new Model();
        model.setId(1);
        model.setEmoji("\uD83D\uDE33");
        return serialize(model);
    }

    @Resource
    private ObjectMapper objectMapper;

    <T> String serialize(T object) {
        try {
            return objectMapper.writeValueAsString(object);
        } catch (JsonProcessingException ex) {
            throw new RuntimeException(ex);
        }
    }
}

2. different results

  • /model
{"id":1,"emoji":"\uD83D\uDE33"}
  • /string
{"id":1,"emoji":"😳"}

3. question

why do we get diffent results?how to get the string() 's result in model()?

@ghost ghost closed this as completed Aug 28, 2018
@ghost
Copy link
Author

ghost commented Aug 28, 2018

The same as FasterXML/jackson-core#223

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants