本文整理汇总了Java中javax.json.JsonReaderFactory类的典型用法代码示例。如果您正苦于以下问题:Java JsonReaderFactory类的具体用法?Java JsonReaderFactory怎么用?Java JsonReaderFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonReaderFactory类属于javax.json包,在下文中一共展示了JsonReaderFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toDictionary
import javax.json.JsonReaderFactory; //导入依赖的package包/类
public static Map<String, Object> toDictionary(String source) throws JsonParseException {
if (source == null) {
return null;
}
JsonObject jsonObject = null;
try {
JsonReaderFactory factory = Json.createReaderFactory(null);
JsonReader jsonReader = factory.createReader(new StringReader(source));
jsonObject = jsonReader.readObject();
jsonReader.close();
} catch (Exception e) {
throw new JsonParseException(e);
}
Map<String, Object> dictionary = new HashMap<String, Object>();
fill_dictionary(dictionary, jsonObject);
return dictionary;
}
示例2: parseSpeaker
import javax.json.JsonReaderFactory; //导入依赖的package包/类
private final List<Speaker> parseSpeaker(URL speakerResource) {
try {
final JsonReaderFactory factory = Json.createReaderFactory(null);
final JsonReader reader = factory.createReader(speakerResource.openStream());
final JsonArray items = reader.readArray();
// parse session objects
final List<Speaker> speaker = new LinkedList<>();
for (final JsonValue item : items) {
final Speaker s = new Speaker((JsonObject) item);
s.setId(String.valueOf(this.speakerId.incrementAndGet()));
speaker.add(s);
}
return speaker;
} catch (Exception e) {
throw new RuntimeException("Failed to parse speaker.json");
}
}
示例3: testBson
import javax.json.JsonReaderFactory; //导入依赖的package包/类
@Test
public void testBson () throws IOException
{
BasicConfigurator.configure ();
String f = "../tests/data/data1.bson";
File file = new File (f.replace ('/', File.separatorChar));
JsonPathProvider provider = new JsonPathProvider ();
Configuration pathConfig = Configuration.defaultConfiguration ().jsonProvider (provider);
JsonPath path = JsonPath.compile ("$..A");
JsonProvider p = new CookJsonProvider ();
HashMap<String, Object> readConfig = new HashMap<String, Object> ();
readConfig.put (CookJsonProvider.FORMAT, CookJsonProvider.FORMAT_BSON);
readConfig.put (CookJsonProvider.ROOT_AS_ARRAY, Boolean.TRUE);
JsonReaderFactory rf = p.createReaderFactory (readConfig);
JsonReader reader = rf.createReader (new FileInputStream (file));
JsonStructure obj = reader.read ();
reader.close ();
JsonValue value = path.read (obj, pathConfig);
Assert.assertEquals ("[1,3,5,7]", provider.toJson (value));
}
示例4: execute
import javax.json.JsonReaderFactory; //导入依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
final JsonReaderFactory readerFactory = Json.createReaderFactory(Collections.<String, Object>emptyMap());
if (source.isFile()) {
generateFile(readerFactory, source);
} else {
final File[] children = source.listFiles(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return name.endsWith(".json");
}
});
if (children == null || children.length == 0) {
throw new MojoExecutionException("No json file found in " + source);
}
for (final File child : children) {
generateFile(readerFactory, child);
}
}
if (attach && project != null) {
project.addCompileSourceRoot(target.getAbsolutePath());
}
}
示例5: testGrowingString
import javax.json.JsonReaderFactory; //导入依赖的package包/类
@Test
public void testGrowingString() throws Throwable {
JsonReaderFactory factory = Json.createReaderFactory(null);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; i++) {
sb.append('x');
String growingString = sb.toString();
String str = "[4, \"\", \"" + growingString + "\", \"\", \"" + growingString + "\", \"\", 400]";
try {
JsonReader reader = factory.createReader(new StringReader(str));
JsonArray array = reader.readArray();
assertEquals(4, array.getInt(0));
assertEquals("", array.getString(1));
assertEquals(growingString, array.getString(2));
assertEquals("", array.getString(3));
assertEquals(growingString, array.getString(4));
assertEquals("", array.getString(5));
assertEquals(400, array.getInt(6));
reader.close();
} catch (Throwable t) {
throw new Throwable("Failed for growingString with length: " + i, t);
}
}
}
示例6: mergeProperties
import javax.json.JsonReaderFactory; //导入依赖的package包/类
public void mergeProperties(final String properties) {
if (StringUtils.isEmpty(properties)) {
return;
}
if (StringUtils.isEmpty(getProperties())) {
setProperties(properties);
return;
}
final JsonReaderFactory fact = Json.createReaderFactory(null);
final JsonReader r1 = fact.createReader(new StringReader(getProperties()));
final JsonObjectBuilder jbf = Json.createObjectBuilder(r1.readObject());
final JsonReader r2 = fact.createReader(new StringReader(getProperties()));
final JsonObject obj2 = r2.readObject();
for (Entry<String, JsonValue> jv : obj2.entrySet()) {
jbf.add(jv.getKey(), jv.getValue());
}
setProperties(jbf.build().toString());
}
示例7: createTokenValidator
import javax.json.JsonReaderFactory; //导入依赖的package包/类
@Override
protected TokenValidator createTokenValidator(Map<String, ?> filterConfig) throws UnavailableException
{
// Pass all of the filter's config to the ReaderFactory factory method. It'll ignore anything it doesn't
// understand (per JSR 353). This way, clients can change the provider using the service locator and configure
// the ReaderFactory using the filter's config.
JsonReaderFactory jsonReaderFactory = JsonProvider.provider().createReaderFactory(filterConfig);
WebKeysClient webKeysClient = HttpClientProvider.provider().createWebKeysClient(filterConfig);
String audience = FilterHelper.getInitParamValue(InitParams.AUDIENCE, filterConfig);
String issuer = FilterHelper.getInitParamValue(InitParams.ISSUER, filterConfig);
return _jwtValidator = new JwtValidatorWithJwk(_minKidReloadTimeInSeconds, webKeysClient, audience, issuer,
jsonReaderFactory);
}
示例8: JwkManager
import javax.json.JsonReaderFactory; //导入依赖的package包/类
JwkManager(long minKidReloadTimeInSeconds, WebKeysClient webKeysClient, JsonReaderFactory jsonReaderFactory)
{
_jsonWebKeyByKID = new TimeBasedCache<>(Duration.ofSeconds(minKidReloadTimeInSeconds), this::reload);
_webKeysClient = webKeysClient;
_jsonReaderFactory = jsonReaderFactory;
// invalidate the cache periodically to avoid stale state
_executor.scheduleAtFixedRate(this::ensureCacheIsFresh, 5, 15, TimeUnit.MINUTES);
}
示例9: JwtValidatorWithCert
import javax.json.JsonReaderFactory; //导入依赖的package包/类
JwtValidatorWithCert(String issuer, String audience, Map<String, RSAPublicKey> publicKeys,
JsonReaderFactory jsonReaderFactory)
{
super(issuer, audience, jsonReaderFactory);
_keys = publicKeys;
}
示例10: JwtValidatorWithJwk
import javax.json.JsonReaderFactory; //导入依赖的package包/类
JwtValidatorWithJwk(long minKidReloadTime, WebKeysClient webKeysClient, String audience, String issuer,
JsonReaderFactory jsonReaderFactory)
{
super(issuer, audience, jsonReaderFactory);
_jwkManager = new JwkManager(minKidReloadTime, webKeysClient, jsonReaderFactory);
}
示例11: createTokenValidator
import javax.json.JsonReaderFactory; //导入依赖的package包/类
@Override
protected TokenValidator createTokenValidator(Map<String, ?> initParams) throws UnavailableException
{
// Like in the OAuthJwtFilter, we'll reuse the config of this filter + the service locator to
// get a JsonReaderFactory
JsonReaderFactory jsonReaderFactory = JsonProvider.provider().createReaderFactory(initParams);
IntrospectionClient introspectionClient = HttpClientProvider.provider()
.createIntrospectionClient(initParams);
return new OpaqueTokenValidator(introspectionClient, jsonReaderFactory);
}
示例12: parseJson
import javax.json.JsonReaderFactory; //导入依赖的package包/类
@Before
public void parseJson() {
JsonReaderFactory factory = Json.createReaderFactory(null);
InputStream in = LibrariesTest.class.getResourceAsStream("libraries.json");
JsonReader reader = factory.createReader(in);
apis = reader.readArray().toArray(new JsonObject[0]);
}
示例13: testJson
import javax.json.JsonReaderFactory; //导入依赖的package包/类
@Test
public void testJson () throws IOException
{
BasicConfigurator.configure ();
String f = "../tests/data/data3.json";
File file = new File (f.replace ('/', File.separatorChar));
JsonPathProvider provider = new JsonPathProvider ();
Configuration pathConfig = Configuration.defaultConfiguration ().jsonProvider (provider);
JsonPath path = JsonPath.compile ("$..A");
JsonProvider p = new CookJsonProvider ();
HashMap<String, Object> readConfig = new HashMap<String, Object> ();
JsonReaderFactory rf = p.createReaderFactory (readConfig);
JsonReader reader = rf.createReader (new FileInputStream (file));
JsonStructure obj = reader.read ();
reader.close ();
JsonValue value = path.read (obj, pathConfig);
Assert.assertEquals ("[1,3,5,7]", provider.toJson (value));
}
示例14: testGrowingStringWithDifferentBufferSizes
import javax.json.JsonReaderFactory; //导入依赖的package包/类
@Test
public void testGrowingStringWithDifferentBufferSizes() throws Throwable {
for (int size = 20; size < 500; size++) {
final int k = size;
Map<String, Object> config = new HashMap<String, Object>() {
{
put("org.apache.johnzon.default-char-buffer", k);
}
};
JsonReaderFactory factory = Json.createReaderFactory(config);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; i++) {
sb.append('x');
String name = sb.toString();
String str = "[4, \"\", \"" + name + "\", \"\", \"" + name + "\", \"\", 400]";
try {
JsonReader reader = factory.createReader(new StringReader(str));
JsonArray array = reader.readArray();
assertEquals(4, array.getInt(0));
assertEquals("", array.getString(1));
assertEquals(name, array.getString(2));
assertEquals("", array.getString(3));
assertEquals(name, array.getString(4));
assertEquals("", array.getString(5));
assertEquals(400, array.getInt(6));
reader.close();
} catch (Throwable t) {
throw new Throwable("Failed for buffer size=" + size + " growingString with length: " + i, t);
}
}
}
}
示例15: contextInitialized
import javax.json.JsonReaderFactory; //导入依赖的package包/类
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
final ClassLoader classLoader = servletContextEvent.getServletContext().getClassLoader();
final JsonReaderFactory reader = newReadFactory();
READER_FACTORY_BY_LOADER.put(classLoader, reader);
servletContextEvent.getServletContext().setAttribute(READER_ATTRIBUTE, reader);
final JsonWriterFactory writer = newWriterFactory();
WRITER_FACTORY_BY_LOADER.put(classLoader, writer);
servletContextEvent.getServletContext().setAttribute(WRITER_ATTRIBUTE, reader);
}