Sha256: 2f7a2e47c0c6963e9f290311c2221c72da4981fdb0b4b11453de6fcf7bd44b64

Contents?: true

Size: 1.81 KB

Versions: 72

Compression:

Stored size: 1.81 KB

Contents

package com.jrjackson;

import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.CompatVersion;
import org.jruby.Ruby;
import org.jruby.RubyHash;
import org.jruby.RubyInstanceConfig;
import org.jruby.ext.bigdecimal.RubyBigDecimal;
import org.jruby.util.ByteList;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayOutputStream;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class RubyAnySerializerTest {
    private static boolean setupDone = false;
    public static Ruby ruby;

    @Before
    public void setUp() throws Exception {
        if (setupDone) return;

        RubyInstanceConfig config_19 = new RubyInstanceConfig();
        config_19.setCompatVersion(CompatVersion.RUBY1_9);
        ruby = Ruby.newInstance(config_19);
        RubyBigDecimal.createBigDecimal(ruby); // we need to do 'require "bigdecimal"'
//        JrubyTimestampExtLibrary.createTimestamp(ruby);
        setupDone = true;
    }


    @Test
    public void testSerialize() throws Exception {
        RubyHash rh = RubyHash.newHash(ruby);
        rh.put("somekey", 123);

        SerializerProvider provider = RubyJacksonModule.createProvider();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JsonGenerator jgen = RubyJacksonModule.factory.createGenerator(
                baos, JsonEncoding.UTF8);

        RubyAnySerializer.instance.serialize(rh, jgen, provider);
        jgen.close();
        ByteList bl = new ByteList(baos.toByteArray(),
                UTF8Encoding.INSTANCE);
        assertThat(bl.toString(), is(equalTo("{\"somekey\":123}")));
    }
}

Version data entries

72 entries across 65 versions & 12 rubygems

Version Path
jrjackson-0.4.18-java src/test/java/com/jrjackson/RubyAnySerializerTest.java
jrjackson-0.4.17-java src/test/java/com/jrjackson/RubyAnySerializerTest.java
jrjackson-0.4.16-java src/test/java/com/jrjackson/RubyAnySerializerTest.java
jrjackson-0.4.15-java src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.14-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.14-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.14-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.14-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/src/test/java/com/jrjackson/RubyAnySerializerTest.java