diff --git a/logstash-core-event-java/spec/event_spec.rb b/logstash-core-event-java/spec/event_spec.rb index 9df705418..03cbffa73 100644 --- a/logstash-core-event-java/spec/event_spec.rb +++ b/logstash-core-event-java/spec/event_spec.rb @@ -104,6 +104,13 @@ describe LogStash::Event do expect(e["foo"]).to be_kind_of(BigDecimal) expect(e["foo"]).to eq(BigDecimal.new(1)) end + + it "should set RubyBignum" do + e = LogStash::Event.new() + e["[foo]"] = -9223372036854776000 + expect(e["foo"]).to be_kind_of(Bignum) + expect(e["foo"]).to eq(-9223372036854776000) + end end context "timestamp" do diff --git a/logstash-core-event-java/src/main/java/com/logstash/Javafier.java b/logstash-core-event-java/src/main/java/com/logstash/Javafier.java index f4f162665..e1e03156b 100644 --- a/logstash-core-event-java/src/main/java/com/logstash/Javafier.java +++ b/logstash-core-event-java/src/main/java/com/logstash/Javafier.java @@ -13,11 +13,14 @@ import org.jruby.RubyBoolean; import org.jruby.RubyFixnum; import org.jruby.RubyTime; import org.jruby.RubySymbol; +import org.jruby.RubyBignum; import org.jruby.ext.bigdecimal.RubyBigDecimal; import com.logstash.ext.JrubyTimestampExtLibrary; import org.jruby.runtime.builtin.IRubyObject; import java.math.BigDecimal; import org.joda.time.DateTime; + +import java.math.BigInteger; import java.util.*; public class Javafier { @@ -66,6 +69,10 @@ public class Javafier { return bd.getBigDecimalValue(); } + public static BigInteger deep(RubyBignum bn) { + return bn.getBigIntegerValue(); + } + public static Timestamp deep(JrubyTimestampExtLibrary.RubyTimestamp t) { return t.getTimestamp(); } @@ -114,6 +121,7 @@ public class Javafier { case RubyTimestamp: return deep((JrubyTimestampExtLibrary.RubyTimestamp)o); case RubyBoolean: return deep((RubyBoolean)o); case RubyFixnum: return deep((RubyFixnum)o); + case RubyBignum: return deep((RubyBignum)o); case RubyTime: return deep((RubyTime)o); case RubySymbol: return deep((RubySymbol)o); case RubyNil: return deep((RubyNil)o); @@ -141,6 +149,7 @@ public class Javafier { RubyHash, RubyBoolean, RubyFixnum, + RubyBignum, RubyObject, RubyNil, RubyTime, diff --git a/logstash-core-event-java/src/test/java/com/logstash/JavafierTest.java b/logstash-core-event-java/src/test/java/com/logstash/JavafierTest.java new file mode 100644 index 000000000..40aaa7b6c --- /dev/null +++ b/logstash-core-event-java/src/test/java/com/logstash/JavafierTest.java @@ -0,0 +1,18 @@ +package com.logstash; + +import org.jruby.Ruby; +import org.jruby.RubyBignum; +import java.math.BigInteger; +import org.junit.Test; +import static org.junit.Assert.*; + +public class JavafierTest { + @Test + public void testRubyBignum() { + RubyBignum v = RubyBignum.newBignum(Ruby.getGlobalRuntime(), "-9223372036854776000"); + + Object result = Javafier.deep(v); + assertEquals(BigInteger.class, result.getClass()); + assertEquals( "-9223372036854776000", result.toString()); + } +} diff --git a/logstash-core-event-java/src/test/java/com/logstash/RubyfierTest.java b/logstash-core-event-java/src/test/java/com/logstash/RubyfierTest.java index af8ecbf0c..5773ce65a 100644 --- a/logstash-core-event-java/src/test/java/com/logstash/RubyfierTest.java +++ b/logstash-core-event-java/src/test/java/com/logstash/RubyfierTest.java @@ -8,6 +8,7 @@ import org.junit.Test; import java.lang.reflect.Method; import java.math.BigDecimal; +import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -217,4 +218,13 @@ public class RubyfierTest { assertEquals(RubyBigDecimal.class, rubyArray.toJavaArray()[0].getClass()); assertEquals(1.0D, ((RubyBigDecimal)rubyArray.toJavaArray()[0]).getDoubleValue(), 0); } + + + @Test + public void testDeepWithBigInteger() { + Object result = Rubyfier.deep(Ruby.getGlobalRuntime(), new BigInteger("1")); + assertEquals(RubyBignum.class, result.getClass()); + assertEquals(1L, ((RubyBignum)result).getLongValue()); + } + }