-
Notifications
You must be signed in to change notification settings - Fork 947
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
deserialize from Json string to Message object #100
Comments
How about this ? final ObjectMapper objectMapper = new ObjectMapper();
final CallbackRequest callbackRequest = objectMapper.readValue(json, CallbackRequest.class); |
Can not deserialize. String json = "{\"type\":\"text\",\"text\":\"Hello, world\"}";
final ObjectMapper objectMapper = new ObjectMapper();
final Message message = objectMapper.readValue(json, Message.class);
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "type" (class com.linecorp.bot.model.message.TextMessage), not marked as ignorable (one known property: "text"])
at [Source: {"type":"text","text":"Hello, world"}; line: 1, column: 38] (through reference chain: com.linecorp.bot.model.message.TextMessage["type"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:62)
…
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3798)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2842) I can now deserialize by adding the following constructor to the TextMessage class. @JsonCreator
public TextMessage(@JsonProperty("text") String text) {
this.text = text;
} |
@hamata5656 |
Oh sorry, you want to deserialize serialized Message JSON.. Please forget my comment. Could you tell me why you want to create deserialized |
Reply is done using LineMessagingClient. |
Thank you your feedback. I was thinking about your case, but it is not easy to provide I'll try to support serialize&deserialization in SDK. But please consider creating your own serialize/deserialize converter, to manage serialization SPEC. |
Thank you for your reply. |
Thank you. |
I want to deserialize from Json string to Message object, but is there something better?
The text was updated successfully, but these errors were encountered: