EMMA Coverage Report (generated Thu Jan 24 13:37:04 CST 2013)
[all classes][org.springframework.batch.item.file.mapping]

COVERAGE SUMMARY FOR SOURCE FILE [JsonLineMapper.java]

nameclass, %method, %block, %line, %
JsonLineMapper.java100% (1/1)100% (2/2)100% (22/22)100% (6/6)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JsonLineMapper100% (1/1)100% (2/2)100% (22/22)100% (6/6)
JsonLineMapper (): void 100% (1/1)100% (8/8)100% (2/2)
mapLine (String, int): Map 100% (1/1)100% (14/14)100% (4/4)

1package org.springframework.batch.item.file.mapping;
2 
3import java.util.Map;
4 
5import org.codehaus.jackson.JsonParser;
6import org.codehaus.jackson.map.MappingJsonFactory;
7import org.springframework.batch.item.file.LineMapper;
8 
9/**
10 * Interpret a line as a Json object and parse it up to a Map. The line should be a standard Json object, starting with
11 * "{" and ending with "}" and composed of <code>name:value</code> pairs separated by commas. Whitespace is ignored,
12 * e.g.
13 * 
14 * <pre>
15 * { "foo" : "bar", "value" : 123 }
16 * </pre>
17 * 
18 * The values can also be Json objects (which are converted to maps):
19 * 
20 * <pre>
21 * { "foo": "bar", "map": { "one": 1, "two": 2}}
22 * </pre>
23 * 
24 * @author Dave Syer
25 * 
26 */
27public class JsonLineMapper implements LineMapper<Map<String, Object>> {
28 
29        private MappingJsonFactory factory = new MappingJsonFactory();
30 
31        /**
32         * Interpret the line as a Json object and create a Map from it.
33         * 
34         * @see LineMapper#mapLine(String, int)
35         */
36        public Map<String, Object> mapLine(String line, int lineNumber) throws Exception {
37                Map<String, Object> result;
38                JsonParser parser = factory.createJsonParser(line);
39                @SuppressWarnings("unchecked")
40                Map<String, Object> token = parser.readValueAs(Map.class);
41                result = token;
42                return result;
43        }
44 
45}

[all classes][org.springframework.batch.item.file.mapping]
EMMA 2.0.5312 (C) Vladimir Roubtsov