Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added auto converting to BigInteger from Integer for to-java since th…

…ere is no literal syntax in Clojure for BigInteger
  • Loading branch information...
commit 5f99587e30eb309d9346a70bdef26f2d0a2b8987 1 parent a813f2f
@cosmin authored
View
2  src/main/clojure/offbytwo/beanhelpers.clj
@@ -57,6 +57,8 @@
(apply setter [instance value]))))
instance))
+(defmethod to-java [BigInteger Integer] [_ value] (bigint value))
+
;; from java
(defmethod from-java Object [instance]
View
2  src/test/clojure/offbytwo/beanhelpers/beanhelperstest.clj
@@ -19,7 +19,7 @@
(deftest java-to-clojure
(let [address (new Address "123 Main St" "Dallas" State/TX "75432")
- person (from-java (Person. "Bob" 30 address))]
+ person (from-java (Person. "Bob" (bigint 30) address))]
(is (= "Bob" (:name person)))
(is (= 30 (:age person)))
(is (= "123 Main St" (:line1 (:address person))))
View
40 src/test/java/offbytwo/beanhelpers/test/Person.java
@@ -1,40 +1,42 @@
package offbytwo.beanhelpers.test;
+import java.math.BigInteger
+
public class Person {
private String name;
- private int age;
+ private BigInteger age;
private Address address;
public Person() {
}
- public Person(String name, int age, Address address) {
+ public Person(String name, BigInteger age, Address address) {
this.name = name;
this.age = age;
this.address = address;
}
public String getName() {
- return name;
- }
+ return name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public int getAge() {
- return age;
- }
+ public BigInteger getAge() {
+ return age;
+ }
- public void setAge(int age) {
- this.age = age;
- }
+ public void setAge(BigInteger age) {
+ this.age = age;
+ }
- public Address getAddress() {
- return address;
- }
+ public Address getAddress() {
+ return address;
+ }
- public void setAddress(Address address) {
- this.address = address;
- }
+ public void setAddress(Address address) {
+ this.address = address;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.