-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
JsonParser.java
56 lines (51 loc) · 1.52 KB
/
JsonParser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package org.basex.build.json;
import java.io.*;
import org.basex.build.xml.*;
import org.basex.core.*;
import org.basex.io.*;
import org.basex.io.parse.json.*;
/**
* This class parses files in the JSON format
* and converts them to XML.
*
* <p>The parser provides some options, which can be specified via the
* {@link MainOptions#JSONPARSER} option.</p>
*
* @author BaseX Team 2005-22, BSD License
* @author Christian Gruen
*/
public final class JsonParser extends XMLParser {
/**
* Constructor.
* @param source document source
* @param opts database options
* @throws IOException I/O exception
*/
public JsonParser(final IO source, final MainOptions opts) throws IOException {
this(source, opts, opts.get(MainOptions.JSONPARSER));
}
/**
* Constructor.
* @param source document source
* @param opts database options
* @param jopts parser options
* @throws IOException I/O exception
*/
public JsonParser(final IO source, final MainOptions opts, final JsonParserOptions jopts)
throws IOException {
super(toXML(source, jopts), opts);
}
/**
* Converts a JSON document to XML.
* @param io input
* @param options parser options
* @return parser
* @throws IOException I/O exception
*/
private static IOContent toXML(final IO io, final JsonParserOptions options) throws IOException {
final JsonConverter conv = JsonConverter.get(options);
final IOContent xml = new IOContent(conv.convert(io).serialize().finish());
xml.name(io.name());
return xml;
}
}