Sha256: 79d9ed3b955b1bd3ad085b0a209de7dd7c9a69c267decbbe2b10280664e1e1e4
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
package com.jrjackson; import java.util.*; import org.jruby.*; import org.jruby.util.RubyDateFormat; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.core.util.VersionUtil; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.fasterxml.jackson.module.afterburner.AfterburnerModule; public class RubyJacksonModule extends SimpleModule { private RubyJacksonModule() { super("JrJacksonStrModule", VersionUtil.versionFor(RubyJacksonModule.class)); } public static ObjectMapper mappedAs(String key) { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule( new AfterburnerModule() ); if (key == "sym") { mapper.registerModule( asSym() ); } else if (key == "raw") { mapper.registerModule( asRaw() ); } else { mapper.registerModule( asStr() ); } mapper.setDateFormat(new RubyDateFormat("yyyy-MM-dd HH:mm:ss z", Locale.US, true)); return mapper; } public static SimpleModule asRaw() { return new RubyJacksonModule().addSerializer( RubySymbol.class, ToStringSerializer.instance ); } public static SimpleModule asSym() { return new RubyJacksonModule().addSerializer( RubySymbol.class, ToStringSerializer.instance ).addDeserializer( Object.class, RubyObjectSymDeserializer.instance ); } public static SimpleModule asStr() { return new RubyJacksonModule().addSerializer( RubySymbol.class, ToStringSerializer.instance ).addDeserializer( Object.class, RubyObjectStrDeserializer.instance ); } }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jrjackson-0.2.0 | src/main/java/com/jrjackson/RubyJacksonModule.java |