lawrencewoodman / mida

A Microdata parser/extractor library for Ruby
http://lawrencewoodman.github.io/mida
Other
77 stars 18 forks source link

to_json on Mida::Item runs forever #5

Open gmcnaughton opened 12 years ago

gmcnaughton commented 12 years ago

Trying to serialize Mida items to json appears to trigger an infinite loop:

require 'open-uri'
require 'mida'

url = 'http://www.youtube.com/watch?v=X4kyojtHJb0'
doc = nil
open(url) { |f| doc = Mida::Document.new(f, url) }
doc.items.to_json # runs forever!

The problem appears to happen when to_json tries to serialize the vocabulary property (probably because vocabulary is huge, or has cyclic references, not sure which!).

I had to work around this by writing a custom serializer that converts Mida::Items to hashes containing only id, type, and properties attributes.