org.springframework.batch.item.file.mapping
Class JsonLineMapper

java.lang.Object
  extended by org.springframework.batch.item.file.mapping.JsonLineMapper
All Implemented Interfaces:
LineMapper<Map<String,Object>>

public class JsonLineMapper
extends Object
implements LineMapper<Map<String,Object>>

Interpret a line as a Json object and parse it up to a Map. The line should be a standard Json object, starting with "{" and ending with "}" and composed of name:value pairs separated by commas. Whitespace is ignored, e.g.

 { "foo" : "bar", "value" : 123 }
 
The values can also be Json objects (which are converted to maps):
 { "foo": "bar", "map": { "one": 1, "two": 2}}
 

Author:
Dave Syer

Constructor Summary
JsonLineMapper()
           
 
Method Summary
 Map<String,Object> mapLine(String line, int lineNumber)
          Interpret the line as a Json object and create a Map from it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonLineMapper

public JsonLineMapper()
Method Detail

mapLine

public Map<String,Object> mapLine(String line,
                                  int lineNumber)
                           throws Exception
Interpret the line as a Json object and create a Map from it.

Specified by:
mapLine in interface LineMapper<Map<String,Object>>
Parameters:
line - to be mapped
lineNumber - of the current line
Returns:
mapped object of type T
Throws:
Exception - if error occured while parsing.
See Also:
LineMapper.mapLine(String, int)


Copyright © 2013 SpringSource. All Rights Reserved.