當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonFactory類代碼示例

本文整理匯總了Java中com.fasterxml.jackson.core.JsonFactory的典型用法代碼示例。如果您正苦於以下問題:Java JsonFactory類的具體用法?Java JsonFactory怎麽用?Java JsonFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonFactory類屬於com.fasterxml.jackson.core包,在下文中一共展示了JsonFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
private StructObjectInspector initialize(final ObjectInspector jsonArg, final ObjectInspector jqArg, final List<ObjectInspector> nameAndTypeArgs) throws UDFArgumentException {
	this.in = Arguments.asString(jsonArg, "JSON");

	try {
		this.jq = JsonQuery.compile(Arguments.asConstantNonNullString(jqArg, "JQ"));
	} catch (final JsonQueryException e) {
		throw new UDFArgumentException("JQ is invalid: " + e.getMessage());
	}

	this.marshaller = ResultObjectMarshallers.create(Arguments.asConstantNonNullStrings(nameAndTypeArgs, "TYPE or NAME:TYPE"));

	this.scope = new Scope();
	this.mapper = new ObjectMapper(new JsonFactory().enable(Feature.ALLOW_UNQUOTED_CONTROL_CHARS));

	return marshaller.objectInspector();
}
 
開發者ID:CyberAgent,項目名稱:hive-jq-udtf,代碼行數:17,代碼來源:JsonQueryUDTF.java

示例2: _testTokenAccess

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
public void _testTokenAccess(JsonFactory jf, boolean useStream) throws Exception
{
    final String DOC = "[ ]";
    JsonParser jp = useStream ?
            jf.createParser(ObjectReadContext.empty(), new ByteArrayInputStream(DOC.getBytes("UTF-8")))
            : jf.createParser(ObjectReadContext.empty(), DOC);
    assertNull(jp.currentToken());
    jp.clearCurrentToken();
    assertNull(jp.currentToken());
    assertNull(jp.getEmbeddedObject());
    assertToken(JsonToken.START_ARRAY, jp.nextToken());
    assertToken(JsonToken.START_ARRAY, jp.currentToken());
    jp.clearCurrentToken();
    assertNull(jp.currentToken());
    // Also: no codec defined by default
    try {
        jp.readValueAsTree();
        fail("Should get exception without codec");
    } catch (UnsupportedOperationException e) {
        verifyException(e, "Operation not supported");
    }
    jp.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:TestParserOverrides.java

示例3: parse

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
/**
 * @param content
 * @throws JsonParseException
 * @throws IOException
 */
public PageInstance parse(String content) throws JsonParseException, IOException {
    JsonFactory f = new JsonFactory();
    JsonParser parser = f.createJsonParser(content);

    JsonToken current = parser.nextToken(); // move to the start of the
    // object

    String instanceId = getNextTextValue("sid", parser); // get instanceId

    String pageId = getNextTextValue("cid", parser); // get pageId

    current = parser.nextToken(); // move to field: segments
    assertExpectedFiled(parser.getCurrentName(), "segments", parser.getCurrentLocation());

    PageInstance pageInstance = new PageInstance();
    pageInstance.setCid(pageId);
    pageInstance.setSid(Long.valueOf(instanceId));
    pageInstance.setSegments(parseSegments(parser));
    return pageInstance;
    // 構建組件樹,用於遞歸渲染
    // pageInstance.buildComponentTree();

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:JacksonPageModelParser.java

示例4: CharsToNameCanonicalizer

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
/**
 * Internal constructor used when creating child instances.
 */
private CharsToNameCanonicalizer(CharsToNameCanonicalizer parent, int flags, int seed,
        TableInfo parentState)
{
    _parent = parent;
    _seed = seed;
    _tableInfo = null; // not used by child tables
    _flags = flags;
    _canonicalize = JsonFactory.Feature.CANONICALIZE_FIELD_NAMES.enabledIn(flags);

    // Then copy shared state
    _symbols = parentState.symbols;
    _buckets = parentState.buckets;

    _size = parentState.size;
    _longestCollisionList = parentState.longestCollisionList;

    // Hard-coded fill factor, 75%
    int arrayLen = (_symbols.length);
    _sizeThreshold = _thresholdSize(arrayLen);
    _indexMask =  (arrayLen - 1);

    // Need to make copies of arrays, if/when adding new entries
    _hashShared = true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:CharsToNameCanonicalizer.java

示例5: _testFailOnWritingStringFromReaderWithTooFewCharacters

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
private void _testFailOnWritingStringFromReaderWithTooFewCharacters(JsonFactory f, boolean useReader) throws Exception{
    JsonGenerator gen;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    if (useReader) {
        gen = f.createGenerator(ObjectWriteContext.empty(), new OutputStreamWriter(bout, "UTF-8"));
    } else {
        gen = f.createGenerator(ObjectWriteContext.empty(), bout, JsonEncoding.UTF8);
    }
    gen.writeStartObject();

    try {
        String testStr = "aaaaaaaaa";
        StringReader reader = new StringReader(testStr);
        gen.writeFieldName("a");
        gen.writeString(reader, testStr.length() + 1);
        gen.flush();
        String json = bout.toString("UTF-8");
        fail("Should not have let "+gen.getClass().getName()+".writeString() ': output = "+json);
    } catch (JsonProcessingException e) {
        verifyException(e, "Didn't read enough from reader");
    }
    gen.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:GeneratorFailFromReaderTest.java

示例6: _testFailOnWritingStringFromNullReader

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
private void _testFailOnWritingStringFromNullReader(JsonFactory f, boolean useReader) throws Exception{
    JsonGenerator gen;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    if (useReader) {
        gen = f.createGenerator(ObjectWriteContext.empty(), new OutputStreamWriter(bout, "UTF-8"));
    } else {
        gen = f.createGenerator(ObjectWriteContext.empty(), bout, JsonEncoding.UTF8);
    }
    gen.writeStartObject();

    try {
        gen.writeFieldName("a");
        gen.writeString(null, -1);
        gen.flush();
        String json = bout.toString("UTF-8");
        fail("Should not have let "+gen.getClass().getName()+".writeString() ': output = "+json);
    } catch (JsonProcessingException e) {
        verifyException(e, "null reader");
    }
    gen.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:GeneratorFailFromReaderTest.java

示例7: _testDupFieldNameWrites

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
private void _testDupFieldNameWrites(JsonFactory f, boolean useReader) throws Exception
{
    JsonGenerator gen;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    if (useReader) {
        gen = f.createGenerator(ObjectWriteContext.empty(), new OutputStreamWriter(bout, "UTF-8"));
    } else {
        gen = f.createGenerator(ObjectWriteContext.empty(), bout, JsonEncoding.UTF8);
    }
    gen.writeStartObject();
    gen.writeFieldName("a");
    
    try {
        gen.writeFieldName("b");
        gen.flush();
        String json = bout.toString("UTF-8");
        fail("Should not have let two consecutive field name writes succeed: output = "+json);
    } catch (JsonProcessingException e) {
        verifyException(e, "can not write a field name, expecting a value");
    }
    gen.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:GeneratorFailTest.java

示例8: _testFailOnWritingFieldNameInRoot

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
private void _testFailOnWritingFieldNameInRoot(JsonFactory f, boolean useReader) throws Exception
{
    JsonGenerator gen;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    if (useReader) {
        gen = f.createGenerator(ObjectWriteContext.empty(), new OutputStreamWriter(bout, "UTF-8"));
    } else {
        gen = f.createGenerator(ObjectWriteContext.empty(), bout, JsonEncoding.UTF8);
    }
    try {
        gen.writeFieldName("a");
        gen.flush();
        String json = bout.toString("UTF-8");
        fail("Should not have let "+gen.getClass().getName()+".writeFieldName() be used in root context: output = "+json);
    } catch (JsonProcessingException e) {
        verifyException(e, "can not write a field name");
    }
    gen.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:GeneratorFailTest.java

示例9: write

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
    try (
            Writer writer = new BufferedWriter(new OutputStreamWriter(output));
            JsonGenerator jsonGenerator = new JsonFactory(new ObjectMapper()).createGenerator(writer)
    ) {
        BigInteger index = BigInteger.ONE;
        jsonGenerator.writeStartArray();
        for (BigInteger v : (Iterable<BigInteger>) bigIntegerStream::iterator) {
            try {
                jsonGenerator.writeObject(new Sequence(index, v));
                index = index.add(BigInteger.ONE);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
        jsonGenerator.writeEndArray();
    } catch (UncheckedIOException ignored) {}
}
 
開發者ID:kishaningithub,項目名稱:infinitestreams,代碼行數:20,代碼來源:ResponseSequenceStreamer.java

示例10: EclipseParser

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
/**
 * Creates a new EclipseParser
 *
 * @param sourceFile String of source file to read
 * @param outJ       JSON parsed out
 * @throws IOException when file can't be opened or errors in reading/writing
 */
public EclipseParser(String sourceFile, PrintStream outJ, boolean prettyprint) throws IOException {

    File file = new File(sourceFile);
    final BufferedReader reader = new BufferedReader(new FileReader(file));
    char[] source = IOUtils.toCharArray(reader);
    reader.close();
    this.parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(source);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);

    final JsonFactory jsonF = new JsonFactory();
    jG = jsonF.createGenerator(outJ);
    if (prettyprint) {
        jG.setPrettyPrinter(new DefaultPrettyPrinter());
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
    }
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
    SimpleModule module = new SimpleModule();
    module.addSerializer(ASTNode.class, new NodeSerializer());
    mapper.registerModule(module);
}
 
開發者ID:bblfsh,項目名稱:java-driver,代碼行數:31,代碼來源:eclipseParser.java

示例11: testParseException

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
public void testParseException() throws Exception
{
    JsonFactory jf = new JsonFactory();
    JsonParser p = jf.createParser(ObjectReadContext.empty(), "  { garbage! }");
    JsonParseException exc = null;
    try {
        p.nextToken();
        p.nextToken();
        fail("Should not get here");
    } catch (JsonParseException e) {
        exc = e;
    }
    p.close();
    byte[] stuff = jdkSerialize(exc);
    JsonParseException result = jdkDeserialize(stuff);
    assertNotNull(result);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:TestJDKSerializability.java

示例12: readJSONFile

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
@Test
public void readJSONFile() {

    // new error-free endpoint
    Endpoint endpoint = resources.createEndpoint("GET", "/test-json-file", "200");

    // write json file on temporary directory
    ObjectMapper mapperJson = new ObjectMapper(new JsonFactory());
    File file = TempIO.buildFile("read-json-file", ".lyre", resources.getDirectory(0));

    try {
        mapperJson.writeValue(file, endpoint);
    } catch (IOException e) {
        fail("Couldn't write on temporary file: " + e.getMessage());
    }

    reader.read(file);

    //should have a object node with json file on it.
    assertThat(reader.getObjectNodes()).isNotEmpty();
    assertThat(reader.getObjectNodes().get(file.getAbsolutePath())).isNotNull();

}
 
開發者ID:groovylabs,項目名稱:lyre,代碼行數:24,代碼來源:ReaderTest.java

示例13: createMapper

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
private ObjectMapper createMapper(JsonFactory mapping, ClassLoader classLoader) {
    ObjectMapper mapper = new ObjectMapper(mapping);
    mapper.addMixIn(MasterSlaveServersConfig.class, MasterSlaveServersConfigMixIn.class);
    mapper.addMixIn(SingleServerConfig.class, SingleSeverConfigMixIn.class);
    mapper.addMixIn(Config.class, ConfigMixIn.class);
    mapper.addMixIn(CodecProvider.class, ClassMixIn.class);
    mapper.addMixIn(ResolverProvider.class, ClassMixIn.class);
    mapper.addMixIn(Codec.class, ClassMixIn.class);
    mapper.addMixIn(RedissonNodeInitializer.class, ClassMixIn.class);
    mapper.addMixIn(LoadBalancer.class, ClassMixIn.class);
    FilterProvider filterProvider = new SimpleFilterProvider()
            .addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept());
    mapper.setFilterProvider(filterProvider);
    mapper.setSerializationInclusion(Include.NON_NULL);

    if (classLoader != null) {
        TypeFactory tf = TypeFactory.defaultInstance()
                .withClassLoader(classLoader);
        mapper.setTypeFactory(tf);
    }
    
    return mapper;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:24,代碼來源:ConfigSupport.java

示例14: toJson

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
/**
 * @return A json representation of the topology. Intended for printing only.
 */
public static final String toJson(ITopology topo, boolean pretty) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    if (pretty)
        mapper.enable(SerializationFeature.INDENT_OUTPUT);

    StringWriter sw = new StringWriter();
    JsonFactory f = mapper.getFactory();

    JsonGenerator g = f.createGenerator(sw);

    g.writeStartObject();
    // use TreeSet to sort the list
    g.writeObjectField("switches", new TreeSet<String>(topo.getSwitches().keySet()));
    g.writeObjectField("links", new TreeSet<String>(topo.getLinks().keySet()));
    g.writeEndObject();
    g.close();

    return sw.toString();
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:23,代碼來源:TopologyPrinter.java

示例15: OutputStreamDemo

import com.fasterxml.jackson.core.JsonFactory; //導入依賴的package包/類
public static void OutputStreamDemo() throws IOException {
    String out = "";
    JsonFactory f = new JsonFactory();
    FileOutputStream fos = new FileOutputStream(new File("user.out.json"));
    JsonGenerator g = f.createGenerator(fos);

    g.writeStartObject();
    g.writeObjectFieldStart("name");
    g.writeStringField("first", "BorLion");
    g.writeStringField("last", "Zhu");
    g.writeEndObject(); // for field 'name'
    g.writeStringField("gender", "MALE");
    g.writeBooleanField("verified", true);
    g.writeBinaryField("userImage", "Rm9vYmFyIQ==".getBytes());
    g.writeEndObject();
    g.writeRaw('\n');
    g.close();

}
 
開發者ID:zhubl,項目名稱:planless,代碼行數:20,代碼來源:Main.java


注:本文中的com.fasterxml.jackson.core.JsonFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。