当前位置: 首页>>代码示例>>Java>>正文


Java JsonProvider类代码示例

本文整理汇总了Java中javax.json.spi.JsonProvider的典型用法代码示例。如果您正苦于以下问题:Java JsonProvider类的具体用法?Java JsonProvider怎么用?Java JsonProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonProvider类属于javax.json.spi包,在下文中一共展示了JsonProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getProvider

import javax.json.spi.JsonProvider; //导入依赖的package包/类
private static JsonProvider getProvider()
{
  Thread thread = Thread.currentThread();
  ClassLoader loader = thread.getContextClassLoader();
  
  synchronized (_providerMap) {
    SoftReference<JsonProvider> providerRef = _providerMap.get(loader);
  
    JsonProvider provider = null;
  
    if (providerRef != null) {
      provider = providerRef.get();
    }
  
    if (provider == null) {
      provider = createProvider();
      
      _providerMap.put(loader, new SoftReference<>(provider));
    }
    
    return provider;
  }
}
 
开发者ID:baratine,项目名称:baratine,代码行数:24,代码来源:Json.java

示例2: convert

import javax.json.spi.JsonProvider; //导入依赖的package包/类
@Override
public JsonObject convert(MarkerPost value) {

	final JsonObjectBuilder builder = JsonProvider.provider()
			.createObjectBuilder();

	builder.add("type", "Feature");
	builder.add("geometry",
			DoublesToPointGeometryJsonObjectConverter.INSTANCE
					.convert(value.getCoordinates()));

	final JsonObjectBuilder properties = JsonProvider.provider()
			.createObjectBuilder();

	properties.add("id", value.getId());
	properties.add("lineId", value.getRailwayLineId());
	properties.add("lineCode", value.getRailwayLineCode());
	properties.add("lineName",
			value.getRailwayLineGeographicalName());
	properties.add("location", value.getLocation());

	builder.add("properties", properties);

	return builder.build();
}
 
开发者ID:highsource,项目名称:tenra,代码行数:26,代码来源:MarkerPostToJsonObjectConverter.java

示例3: start

import javax.json.spi.JsonProvider; //导入依赖的package包/类
@Override
public void start() throws IOException {
	if (generator != null) {
		throw new IllegalStateException(
				"Invalid state, serializer was already started.");
	} else {
		os = new FileOutputStream(ouputFile);
		generator = JsonProvider
				.provider()
				.createGeneratorFactory(
						Collections.singletonMap(
								JsonGenerator.PRETTY_PRINTING, true))
				.createGenerator(os);

		generator.writeStartObject().write("type", "FeatureCollection")
				.writeStartArray("features");
	}
}
 
开发者ID:highsource,项目名称:tenra,代码行数:19,代码来源:FeatureCollectionSerializer.java

示例4: testJsonObject

import javax.json.spi.JsonProvider; //导入依赖的package包/类
@Test
public void testJsonObject() {
    final JsonObjectBuilder objBuilder = JsonProvider.provider().createObjectBuilder();
    objBuilder.add("boolTrue", Boolean.TRUE).add("boolFalse", Boolean.FALSE)
            .addNull("null").add("str", "String");

    JsonArrayBuilder arrBuilder = JsonProvider.provider().createArrayBuilder();
    arrBuilder.add(11L).add(Boolean.FALSE).add(BigDecimal.TEN);
    objBuilder.add("array", arrBuilder);

    JsonObject object = objBuilder.build();

    String expected = "{\"boolTrue\":true,\"boolFalse\":false,\"null\":null,\"str\":\"String\",\"array\":[11,false,10]}";
    assertEquals(expected, jsonb.toJson(object));

    JsonObject result = jsonb.fromJson(expected, JsonObject.class);

    assertEquals(object, result);
}
 
开发者ID:eclipse,项目名称:yasson,代码行数:20,代码来源:JsonpTest.java

示例5: testBson

import javax.json.spi.JsonProvider; //导入依赖的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));
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:26,代码来源:JsonPathProviderTest.java

示例6: readerWriterTest

import javax.json.spi.JsonProvider; //导入依赖的package包/类
@Test
public void readerWriterTest () throws IOException
{
	File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
	JsonProvider provider = new CookJsonProvider ();

	// create reader
	HashMap<String, Object> readConfig = new HashMap<String, Object> ();
	JsonReaderFactory rf = provider.createReaderFactory (readConfig);
	JsonReader reader = rf.createReader (new InputStreamReader (new FileInputStream (file), BOM.utf8));
	JsonStructure obj = reader.read ();
	reader.close ();

	// write it out
	File dstFile = testFolder.newFile ();
	HashMap<String, Object> writeConfig = new HashMap<String, Object> ();
	JsonWriterFactory wf = provider.createWriterFactory (writeConfig);
	JsonWriter writer = wf.createWriter (new OutputStreamWriter (new FileOutputStream (dstFile), BOM.utf8));
	writer.write (obj);
	writer.close ();

	Assert.assertEquals (file.length (), dstFile.length ());
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:24,代码来源:JsonReaderWriterFactoryTest.java

示例7: charsetTest

import javax.json.spi.JsonProvider; //导入依赖的package包/类
@Test
public void charsetTest () throws IOException
{
	File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
	JsonProvider provider = new CookJsonProvider ();

	// create reader
	HashMap<String, Object> readConfig = new HashMap<String, Object> ();
	JsonReaderFactory rf = provider.createReaderFactory (readConfig);
	JsonReader reader = rf.createReader (new FileInputStream (file), BOM.utf8);
	JsonStructure obj = reader.read ();
	reader.close ();

	// write it out
	File dstFile = testFolder.newFile ();
	HashMap<String, Object> writeConfig = new HashMap<String, Object> ();
	JsonWriterFactory wf = provider.createWriterFactory (writeConfig);
	JsonWriter writer = wf.createWriter (new FileOutputStream (dstFile), BOM.utf8);
	writer.write (obj);
	writer.close ();

	Assert.assertEquals (file.length (), dstFile.length ());
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:24,代码来源:JsonReaderWriterFactoryTest.java

示例8: streamTest

import javax.json.spi.JsonProvider; //导入依赖的package包/类
@Test
public void streamTest () throws IOException
{
	File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
	JsonProvider provider = new CookJsonProvider ();

	// create reader
	HashMap<String, Object> readConfig = new HashMap<String, Object> ();
	JsonReaderFactory rf = provider.createReaderFactory (readConfig);
	JsonReader reader = rf.createReader (new FileInputStream (file));
	JsonStructure obj = reader.read ();
	reader.close ();

	// write it out
	File dstFile = testFolder.newFile ();
	HashMap<String, Object> writeConfig = new HashMap<String, Object> ();
	JsonWriterFactory wf = provider.createWriterFactory (writeConfig);
	JsonWriter writer = wf.createWriter (new FileOutputStream (dstFile));
	writer.write (obj);
	writer.close ();

	Assert.assertEquals (file.length (), dstFile.length ());
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:24,代码来源:JsonReaderWriterFactoryTest.java

示例9: testFile

import javax.json.spi.JsonProvider; //导入依赖的package包/类
void testFile (String f1, String f2, boolean smallBuf) throws IOException
{
	File file1 = new File (f1.replace ('/', File.separatorChar));
	File file2 = new File (f2.replace ('/', File.separatorChar));

	StringWriter out1 = new StringWriter ();
	JsonParser p1 = getJsonParser (file1, smallBuf);
	JsonGenerator g1 = new TextJsonGenerator (out1);
	Utils.convert (p1, g1);
	p1.close ();
	g1.close ();

	StringWriter out2 = new StringWriter ();
	JsonProvider provider = new org.glassfish.json.JsonProviderImpl ();
	JsonParser p2 = provider.createParser (new FileInputStream (file2));
	JsonGenerator g2 = new TextJsonGenerator (out2);
	Utils.convert (p2, g2);
	p2.close ();
	g2.close ();

	Assert.assertEquals (out1.toString (), out2.toString ());
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:23,代码来源:CommentTest.java

示例10: testFile

import javax.json.spi.JsonProvider; //导入依赖的package包/类
void testFile (String f) throws IOException
{
	File file = new File (f.replace ('/', File.separatorChar));

	JsonProvider provider = new org.glassfish.json.JsonProviderImpl ();

	StringWriter out1 = new StringWriter ();
	JsonParser p1 = provider.createParser (new FileInputStream (file));

	HashMap<String, Object> config = new HashMap<String, Object> ();
	config.put (JsonGenerator.PRETTY_PRINTING, Boolean.TRUE);
	JsonGenerator g1 = new CookJsonProvider ().createGeneratorFactory (config).createGenerator (out1);
	Utils.convert (p1, g1);
	p1.close ();
	g1.close ();

	String original = Utils.getString (file);

	Assert.assertEquals (out1.toString (), original);
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:21,代码来源:PrettyTextJsonGeneratorTest.java

示例11: eventCount

import javax.json.spi.JsonProvider; //导入依赖的package包/类
private void eventCount (String f, int expect)  throws IOException
{
	File file = new File (f.replace ('/', File.separatorChar));

	JsonValue value;
	TextJsonParser p = getJsonParser (file);
	p.next ();
	value = p.getValue ();
	p.close ();

	JsonProvider provider = new CookJsonProvider ();
	JsonParser p2 = createParser (provider, value);

	int count;
	for (count = 0; p2.hasNext (); ++count)
		p2.next ();
	p2.close ();

	Assert.assertEquals (expect, count);;
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:21,代码来源:JsonStructureParserTest.java

示例12: testDefault

import javax.json.spi.JsonProvider; //导入依赖的package包/类
@Test
public void testDefault ()
{
	JsonProvider provider = new CookJsonProvider ();
	JsonObjectBuilder builder = provider.createObjectBuilder ();
	JsonObject obj = builder
		.add ("string", "test")
		.add ("int", 1234)
		.add ("true", true)
		.add ("false", false)
		.addNull ("null")
		.build ();
	Assert.assertEquals ("test", obj.getString ("string", "asdf"));
	Assert.assertEquals (1234, obj.getInt ("int", 890));
	Assert.assertEquals (true, obj.getBoolean ("true", false));
	Assert.assertEquals (false, obj.getBoolean ("false", true));

	Assert.assertEquals ("test", obj.getString ("no", "test"));
	Assert.assertEquals (1234, obj.getInt ("no", 1234));
	Assert.assertEquals (true, obj.getBoolean ("no", true));
	Assert.assertEquals (false, obj.getBoolean ("no", false));
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:23,代码来源:CookJsonObjectTest.java

示例13: testGet

import javax.json.spi.JsonProvider; //导入依赖的package包/类
@Test
public void testGet ()
{
	JsonProvider provider = new CookJsonProvider ();
	JsonObjectBuilder builder = provider.createObjectBuilder ();
	JsonObject obj = builder
		.add ("string", "test")
		.add ("int", 1234)
		.add ("true", true)
		.add ("false", false)
		.addNull ("null")
		.build ();
	Assert.assertEquals ("test", obj.getString ("string"));
	Assert.assertEquals (1234, obj.getInt ("int"));
	Assert.assertEquals (true, obj.getBoolean ("true"));
	Assert.assertEquals (false, obj.getBoolean ("false"));
	Assert.assertEquals (true, obj.isNull ("null"));
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:19,代码来源:CookJsonObjectTest.java

示例14: testDefault

import javax.json.spi.JsonProvider; //导入依赖的package包/类
@Test
public void testDefault ()
{
	JsonProvider provider = new CookJsonProvider ();
	JsonArrayBuilder builder = provider.createArrayBuilder ();
	JsonArray array = builder
		.add ("test")
		.add (1234)
		.add (true)
		.add (false)
		.addNull ()
		.build ();
	Assert.assertEquals ("test", array.getString (0, "asdf"));
	Assert.assertEquals (1234, array.getInt (1, 890));
	Assert.assertEquals (true, array.getBoolean (2, false));
	Assert.assertEquals (false, array.getBoolean (3, true));

	Assert.assertEquals ("test", array.getString (11, "test"));
	Assert.assertEquals (1234, array.getInt (11, 1234));
	Assert.assertEquals (true, array.getBoolean (11, true));
	Assert.assertEquals (false, array.getBoolean (11, false));
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:23,代码来源:CookJsonArrayTest.java

示例15: testGet

import javax.json.spi.JsonProvider; //导入依赖的package包/类
@Test
public void testGet ()
{
	JsonProvider provider = new CookJsonProvider ();
	JsonArrayBuilder builder = provider.createArrayBuilder ();
	JsonArray array = builder
		.add ("test")
		.add (1234)
		.add (true)
		.add (false)
		.addNull ()
		.build ();
	Assert.assertEquals ("test", array.getString (0));
	Assert.assertEquals (1234, array.getInt (1));
	Assert.assertEquals (true, array.getBoolean (2));
	Assert.assertEquals (false, array.getBoolean (3));
	Assert.assertEquals (true, array.isNull (4));
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:19,代码来源:CookJsonArrayTest.java


注:本文中的javax.json.spi.JsonProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。