class Leafy::Json::JsonWriter

Public Class Methods

new( jacksonModule ) click to toggle source
# File leafy-rack/lib/leafy/json/json_writer.rb, line 7
def initialize( jacksonModule )
  @mapper = ObjectMapper.new.registerModule( jacksonModule )
end

Public Instance Methods

data() click to toggle source
# File leafy-rack/lib/leafy/json/json_writer.rb, line 11
def data
  raise 'need implementation'
end
to_json( data, pretty = false ) click to toggle source
# File leafy-rack/lib/leafy/json/json_writer.rb, line 15
def to_json( data, pretty = false )
  # TODO make this stream
  output = java.io.ByteArrayOutputStream.new
  writer( pretty ).writeValue(output, data);
  output.to_s
end

Private Instance Methods

writer( pretty ) click to toggle source
# File leafy-rack/lib/leafy/json/json_writer.rb, line 24
def writer( pretty )
  if pretty
    @mapper.writerWithDefaultPrettyPrinter
  else
    @mapper.writer
  end
end