Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

handle generation of futures #22

Merged
merged 1 commit into from

2 participants

@strongh

When passed futures to generate, get the value of the object and generate it. Simple test included.

@lancepantz lancepantz merged commit 542cdaf into from
@lancepantz
Collaborator

Hi Homer-
I merged your code, then made it a generic for anything that implements IDeref. Thanks for the contribution!
-lance

@lancepantz
Collaborator

forgot to add, i release 0.5.3 to clojars, which contains what you need

@strongh

Good call generalizing to IDeref!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 14, 2012
  1. handle generation of futures

    Homer Strong authored
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 3 deletions.
  1. +4 −1 src/jvm/clj_json/JsonExt.java
  2. +4 −2 test/clj_json/core_test.clj
View
5 src/jvm/clj_json/JsonExt.java
@@ -8,6 +8,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.concurrent.Future;
import java.math.BigDecimal;
import clojure.lang.IFn;
import clojure.lang.Keyword;
@@ -88,7 +89,9 @@ public void generate(Object obj) throws Exception{
generate(o);
}
jg.writeEndArray();
- }
+ } else if (obj instanceof Future) {
+ generate(((Future) obj).get());
+ }
else {
throw new Exception("Cannot generate " + obj);
}
View
6 test/clj_json/core_test.clj
@@ -74,6 +74,8 @@
(deftest test-bigdecimal
(is (= "{\"data1\":1,\"data2\":1.11}"
- (json/generate-string {:data1 1M :data2 1.11M})))
-)
+ (json/generate-string {:data1 1M :data2 1.11M}))))
+(deftest test-future
+ (is (= "42"
+ (json/generate-string (future 42)))))
Something went wrong with that request. Please try again.