Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "msgpack"
- require "json"
- require "./GenJSON/*"
- macro mp_class (class_name, props)
- class {{class_name}}
- MessagePack.mapping({{props}})
- def to_json(json : JSON::Builder)
- json.object do
- {% for propName in props %}
- json.field "{{propName}}", self.{{propName}}
- {% end %}
- end
- end
- end
- end
- module GenJSON
- mp_class(Host, {hostid: Int32, host: String, name: String, type: Int32})
- puts Host.from_msgpack(
- {
- "host" => "vm-host-01.example.com",
- "name" => "Virtual machine #01",
- "hostid" => 1234,
- "type" => 1
- }.to_msgpack ).to_json
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement