Package dev.langchain4j.data.message
Class GsonChatMessageJsonCodec
java.lang.Object
dev.langchain4j.data.message.GsonChatMessageJsonCodec
- All Implemented Interfaces:
ChatMessageJsonCodec
A codec for serializing and deserializing
ChatMessage
objects to and from JSON.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionmessageFromJson
(String json) Deserializes a JSON string to aChatMessage
object.messagesFromJson
(String json) Deserializes a JSON string to a list ofChatMessage
objects.messagesToJson
(List<ChatMessage> messages) Serializes a list ofChatMessage
objects to a JSON string.messageToJson
(ChatMessage message) Serializes aChatMessage
object to a JSON string.
-
Constructor Details
-
GsonChatMessageJsonCodec
public GsonChatMessageJsonCodec()Constructs a newGsonChatMessageJsonCodec
.
-
-
Method Details
-
messageFromJson
Description copied from interface:ChatMessageJsonCodec
Deserializes a JSON string to aChatMessage
object.- Specified by:
messageFromJson
in interfaceChatMessageJsonCodec
- Parameters:
json
- the JSON string.- Returns:
- the deserialized
ChatMessage
object.
-
messagesFromJson
Description copied from interface:ChatMessageJsonCodec
Deserializes a JSON string to a list ofChatMessage
objects.- Specified by:
messagesFromJson
in interfaceChatMessageJsonCodec
- Parameters:
json
- the JSON string.- Returns:
- the deserialized list of
ChatMessage
objects.
-
messageToJson
Description copied from interface:ChatMessageJsonCodec
Serializes aChatMessage
object to a JSON string.- Specified by:
messageToJson
in interfaceChatMessageJsonCodec
- Parameters:
message
- theChatMessage
object.- Returns:
- the serialized JSON string.
-
messagesToJson
Description copied from interface:ChatMessageJsonCodec
Serializes a list ofChatMessage
objects to a JSON string.- Specified by:
messagesToJson
in interfaceChatMessageJsonCodec
- Parameters:
messages
- the list ofChatMessage
objects.- Returns:
- the serialized JSON string.
-