Coder Social home page Coder Social logo

Comments (8)

be-hase avatar be-hase commented on August 21, 2024

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);

ref:
https://github.com/line/line-bot-sdk-java/blob/master/line-bot-servlet/src/main/java/com/linecorp/bot/servlet/LineBotCallbackRequestParser.java

from line-bot-sdk-java.

hamata5656 avatar hamata5656 commented on August 21, 2024

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.

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

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

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

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.

hamata5656 avatar hamata5656 commented on August 21, 2024

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.

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

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.

hamata5656 avatar hamata5656 commented on August 21, 2024

Thank you for your reply.
I'll create my own serialize / deserialize converter.

from line-bot-sdk-java.

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

Thank you.

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.