Class: Leafy::Json::JsonWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/leafy/json/json_writer.rb

Direct Known Subclasses

HealthWriter, MetricsWriter

Instance Method Summary collapse

Constructor Details

#initialize(jacksonModule) ⇒ JsonWriter

Returns a new instance of JsonWriter.



7
8
9
# File 'lib/leafy/json/json_writer.rb', line 7

def initialize( jacksonModule )
  @mapper = ObjectMapper.new.registerModule( jacksonModule )
end

Instance Method Details

#dataObject



11
12
13
# File 'lib/leafy/json/json_writer.rb', line 11

def data
  raise 'need implementation'
end

#to_json(data, pretty = false) ⇒ Object



15
16
17
18
19
20
# File '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