views:

142

answers:

2

Using beanstalkd and putting a job in tube/queue that contains a hash that is YAML::Syck encoded (with $YAML::Syck::ImplicitTyping = 1).

I need some syntax help on the Java end, as to how to decode handle that string pulled from the beanstalkd job. The Perl hash ends up being encoded as a YAML string that looks like this:

--- NameFirst
--- Mike
--- NameLast
--- Smith
--- DOB
--- 07/07/2007

These YAML records (as above) are only processed one at a time. So, given that string above, how in the world do I get JYaml to read that in, and decode into an object class with methods like:

Customer.NameFirst
Customer.NameLast
Customer.DOB

+3  A: 

I suspect you are doing Dump(%hash) where you should be doing Dump(\%hash). The former dumps an independent list of alternating keys and values; the latter dumps the hash with each value being associated with a key, like:

---
DOB: 07/07/2007
NameFirst: Mike
NameLast: Smith
ysth
Yes, I was just about to edit my original question. My YAML string now looks exactly as you posted it. Now, when I'm in Java and I grab the data using beanstalkd client: // Grab job data byte[] dstBytes = job.getData(); // inside temp is exactly what you have above String person = new String(dstBytes);How would my class definition and JYaml code look like to take that "person" YAML string, and have it respond to something like: System.out.println(Customer.NameFirst);?? Thanks.
Dang it, sorry about the formatting.. no preview in the comments field.
A: 

You might consider switching to SnakeYAML. I too generate YAML from Perl via YAML::Syck to be consumed by Java. I ran into some interop problems with JYaml where YAML::Syck was generating valid YAML that JYaml couldn't parse. Since switching to SnakeYAML the only interop problems I've had have been bugs in YAML::Syck. This answer has more details on my experience with SnakeYAML.

toolbear74