Comments (8)
What do you mean?
from line-bot-sdk-java.
When I try to map the Json String to the CallbackRequest java class, I get the error:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "type" (class com.linecorp.bot.model.event.source.UserSource), not marked as ignorable (one known property: "userId"])
at [Source: {"events":[{"type":"message","replyToken":"82dce99766c64c44800ab4a5a346820f","source":{"userId":"U3eee52852c65d80f6d888695c6b76f6b","type":"user"},"timestamp":1489434877017,"message":{"type":"text","id":"5777707649369","text":"hi"}}]}; line: 1, column: 146] (through reference chain: com.linecorp.bot.model.event.CallbackRequest["events"]->java.util.ArrayList[0]->com.linecorp.bot.model.event.MessageEvent["source"]->com.linecorp.bot.model.event.source.UserSource["type"])
to reproduce this error use this test:
from line-bot-sdk-java.
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.linecorp.bot.model.event.CallbackRequest;
import org.junit.Test;
import static org.fest.assertions.Assertions.assertThat;
public class LineAPITest {
@Test
public void getEvents() throws Exception {
String json = "{\"events\":[{\"type\":\"message\",\"replyToken\":\"82dce99766c64c44800ab4a5a346820f\",\"source\":{\"userId\":\"U3eee52852c65d80f6d888695c6b76f6b\",\"type\":\"user\"},\"timestamp\":1489434877017,\"message\":{\"type\":\"text\",\"id\":\"5777707649369\",\"text\":\"hi\"}}]}";
ObjectMapper m = new ObjectMapper();
m.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
CallbackRequest req = m.readValue(json, CallbackRequest.class);
assertThat(req).isNotNull();
}
}
from line-bot-sdk-java.
@tokuhirom if you have any questions, please feel free to contact me directly (didn't get the notifications)
from line-bot-sdk-java.
@tokuhirom fails with
<dependency>
<groupId>com.linecorp.bot</groupId>
<artifactId>line-bot-api-client</artifactId>
<version>1.6.0</version>
</dependency>
from line-bot-sdk-java.
@electrobabe
There are some custom configuration is needed to deserialize event json into model.
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#L94-L102?
Using LineBotCallbackRequestParser
is better to deserialize events.
And if you use spring boot integration, received JSON deserialization and send serialized JSON are unnecessary work.
from line-bot-sdk-java.
alright! it was simply the configuration of the ObjectMapper, that was missing:
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
BTW I don't use Spring Boot but Spring Web
from line-bot-sdk-java.
I am happy that your issue solved. 👍
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.