in reply to Re: JSON.pm returning "false" instead of false
in thread JSON.pm returning "false" instead of false

Well I'm using this as a serializer object inside a Mojo App......so I'm getting a database response and converting it into JSON. I have a value that is returned as $hash->{'leaf'} = JSON::false but it is returning as "leaf": "false". I'm pretty sure I'm calling the serialize function but I'll have to trace it through. This is using Mojo, which has a render_json function and I'm over-riding Mojo::JSON with a controller that does this:
BEGIN { # install JSON and JSON::XS if you can! eval 'use JSON -convert_blessed_universally;'; eval ( $@ ? 'sub HAS_JSON(){ 0 }' : 'sub HAS_JSON(){ 1 }' ); }
Which makes it all a bit complicated. I just noticed that the return wasn't what I expected. I'll double check that my serialize is getting called but I'm pretty sure it is.

Replies are listed 'Best First'.
Re^3: JSON.pm returning "false" instead of false
by ikegami (Patriarch) on Apr 12, 2010 at 22:31 UTC

    I'm pretty sure I'm calling the serialize function but I'll have to trace it through.

    I meant in the code you provided. In other words, you didn't demonstrate a problem since the code you posted didn't do anything at all. My guesses as to what your code might be proved to be a waste of time since I could not reproduce the problem you describe.

    Please provide minimal code that reproduces the problem. The code you posted works fine when I call it. I even tried replacing the use statement with the BEGIN block you more recently provided.

      It's a big app so I didn't want to bog anyone down with the details, although I should have provided a test case. Your answer actually brought me to the solution though. It turns out that the $self->render_json method from Mojo was not being over-ridden correctly, and was therefore never calling the "serialize" method just as you suggested. So, I thank you very much for giving me a hint and leading me down the correct path. Next time, I will provide a test case that demonstrates the issue a little more clearly.

        That's the point of making a minimal example.

        1. It is small enough to debug.
        2. It demonstrates the problem.

        When you do those steps, you often find the answer yourself. If not, you'll know what to look at in the simple examples for next time.

        Thanks for all your feedback, sadly I know this already I was just being lazy. Ishould have taken the time to create a complete working test example and in doing so I would have found the problem. I completely agree that creating a base case makes it much easier for people to comment on and often allows me to find the solution myself before asking anyone. Thanks again for all the feedback.