Module: A2A::Extensions::JSONDeserialization::ClassMethods

Defined in:
lib/a2a/extensions/json_deserialization.rb

Overview

Class methods added to the class that includes JsonDeserialization

Instance Method Summary collapse

Instance Method Details

#from_json(json) ⇒ ProtocolStruct

Creates a new instance from a JSON string

Examples:

Create a Google Maps Agent Card from JSON

json_string = "{\n  \"name\": \"Google Maps Agent\",\n  \"description\": \"Plan routes, remember places, and generate directions\",\n  \"url\": \"https://maps-agent.google.com\",\n  \"provider\": {\n    \"organization\": \"Google\",\n    \"url\": \"https://google.com\"\n  },\n  \"version\": \"1.0.0\",\n  \"capabilities\": {\n    \"streaming\": true,\n    \"pushNotifications\": false\n  },\n  \"skills\": [\n    {\n      \"id\": \"route-planner\",\n      \"name\": \"Route planning\",\n      \"description\": \"Helps plan routing between two locations\"\n    }\n  ]\n}\n"
agent_card = A2A::AgentCard.from_json(json_string)

Parameters:

  • json (String)

    JSON string to parse

Returns:

  • (ProtocolStruct)

    A new instance of the appropriate class



45
46
47
# File 'lib/a2a/extensions/json_deserialization.rb', line 45

def from_json(json)
  new(MultiJson.load(json, symbolize_keys: true))
end