Coder Social home page Coder Social logo

Comments (8)

tokuhirom avatar tokuhirom commented on August 21, 2024

What do you mean?

from line-bot-sdk-java.

electrobabe avatar electrobabe commented on August 21, 2024

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.

electrobabe avatar electrobabe commented on August 21, 2024
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.

electrobabe avatar electrobabe commented on August 21, 2024

@tokuhirom if you have any questions, please feel free to contact me directly (didn't get the notifications)

from line-bot-sdk-java.

electrobabe avatar electrobabe commented on August 21, 2024

@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.

kazuki-ma avatar kazuki-ma commented on August 21, 2024

@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.

electrobabe avatar electrobabe commented on August 21, 2024

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.

kazuki-ma avatar kazuki-ma commented on August 21, 2024

I am happy that your issue solved. 👍

from line-bot-sdk-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.