Comments (8)
How about this ?
We support JSON-deserialize by Jackson.
( https://github.com/FasterXML/jackson )
final ObjectMapper objectMapper = new ObjectMapper();
final CallbackRequest callbackRequest = objectMapper.readValue(json, CallbackRequest.class);
from line-bot-sdk-java.
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;
}
from line-bot-sdk-java.
@hamata5656
Need some custom configuration.
Could you refer https://github.com/line/line-bot-sdk-java/blob/master/line-bot-servlet/src/main/java/com/linecorp/bot/servlet/LineBotCallbackRequestParser.java#L95-L101 ?
from line-bot-sdk-java.
Oh sorry, you want to deserialize serialized Message JSON.. Please forget my comment.
Could you tell me why you want to create deserialized Message
string?
For push/reply message, using LineMessagingClient
is better.
from line-bot-sdk-java.
Reply is done using LineMessagingClient.
However, since I want to manage the message to reply in one table, I want to keep it as a JSON String.
from line-bot-sdk-java.
Thank you your feedback.
I was thinking about your case, but it is not easy to provide Message
JSON serialize&deserialize feature, especially with compatibility consideration.
I'll try to support serialize&deserialization in SDK.
But please consider creating your own serialize/deserialize converter, to manage serialization SPEC.
from line-bot-sdk-java.
Thank you for your reply.
I'll create my own serialize / deserialize converter.
from line-bot-sdk-java.
Thank you.
from line-bot-sdk-java.
Related Issues (20)
- [Feature Request] Http proxy support in version 7 HOT 7
- [BUG] LineBlobClient UnauthorizedException response HOT 7
- [Question] Line stickers HOT 1
- [Question] version 6.x End of Life Date HOT 1
- [Question] version 6.x End of Life Date continued HOT 2
- [BUG] Line Module Channel unable to attach bot to the line module HOT 1
- [Feature Request] mimeType in BlobContent HOT 1
- Please annotate field @Nullable or @NotNull HOT 8
- [Feature Request] Some enums are missing in v7 HOT 2
- Proposal: Switch from Retrofit2 to OkHttp3 HOT 1
- [Feature Request] Disable the logger "com.linecorp.bot.client.wire" HOT 1
- [BUG] NPE thrown by MessagingApiClientException#getDetails() HOT 2
- Get content transcoding status and a preview image HOT 2
- Get content transcoding status and a preview image HOT 1
- @All in the mention property of the webhooks HOT 2
- [BUG] Cannot resolve method 'getMessageContent' in 'LineMessagingClient' HOT 3
- Time to development 7.x
- Update openapi spec periodically HOT 1
- Release artifacts via github releases HOT 3
- Type name missmatch in openapi code generation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from line-bot-sdk-java.