Search in sources :

Example 46 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveScrollDescendants method writeJSONBlob.

protected Blob writeJSONBlob(ScrollFileSystemItemList scrollFSIList) throws IOException {
    StringWriter writer = new StringWriter();
    JsonFactory factory = new JsonFactory();
    try (JsonGenerator jg = factory.createGenerator(writer)) {
        jg.setCodec(new ObjectMapper());
        jg.writeStartObject();
        jg.writeStringField("scrollId", scrollFSIList.getScrollId());
        jg.writeObjectField("fileSystemItems", scrollFSIList);
        jg.writeEndObject();
    }
    return Blobs.createJSONBlob(writer.toString());
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 47 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project whole by wholeplatform.

the class JSONLDPersistenceKit method doReadModel.

protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
    JsonFactory factory = new JsonFactory();
    JsonParser parser = factory.createParser(pp.getInputStream());
    parser.disable(Feature.AUTO_CLOSE_SOURCE);
    try {
        return new JSONLDEntityDecoder().clone(new JSONParserTemplateFactory(parser).create());
    } finally {
        parser.close();
    }
}
Also used : JSONLDEntityDecoder(org.whole.lang.json.util.JSONLDEntityDecoder) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JSONParserTemplateFactory(org.whole.lang.json.util.JSONParserTemplateFactory) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 48 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project syndesis by syndesisio.

the class JsonRecordSupport method jsonStreamToRecords.

public static void jsonStreamToRecords(Set<String> indexes, String dbPath, InputStream is, Consumer<JsonRecord> consumer) throws IOException {
    try (JsonParser jp = new JsonFactory().createParser(is)) {
        jsonStreamToRecords(indexes, jp, dbPath, consumer);
        JsonToken jsonToken = jp.nextToken();
        if (jsonToken != null) {
            throw new JsonParseException(jp, "Document did not terminate as expected.");
        }
    }
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 49 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafRequestContext method createLightWeightCloneFromJson.

/**
 * Resurrect the BroadleafRequestContext state based on a JSON representation.
 *
 * @param Json
 * @param em
 * @return
 */
public static BroadleafRequestContext createLightWeightCloneFromJson(String Json, EntityManager em) {
    BroadleafRequestContext context = new BroadleafRequestContext();
    JsonFactory factory = new JsonFactory();
    ObjectMapper mapper = new ObjectMapper(factory);
    TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {
    };
    HashMap<String, String> json;
    try {
        json = mapper.readValue(Json, typeRef);
    } catch (IOException e) {
        throw ExceptionHelper.refineException(e);
    }
    if (!json.get("ignoreSite").equals("null")) {
        context.setIgnoreSite(Boolean.valueOf(json.get("ignoreSite")));
    }
    if (!json.get("sandBox").equals("null")) {
        context.setSandBox(em.find(SandBoxImpl.class, Long.parseLong(json.get("sandBox"))));
    }
    if (!json.get("nonPersistentSite").equals("null")) {
        context.setNonPersistentSite(em.find(SiteImpl.class, Long.parseLong(json.get("nonPersistentSite"))));
    }
    if (!json.get("enforceEnterpriseCollectionBehaviorState").equals("null")) {
        context.setEnforceEnterpriseCollectionBehaviorState(EnforceEnterpriseCollectionBehaviorState.valueOf(json.get("enforceEnterpriseCollectionBehaviorState")));
    }
    if (!json.get("admin").equals("null")) {
        context.setAdmin(Boolean.valueOf(json.get("admin")));
    }
    if (!json.get("adminUserId").equals("null")) {
        context.setAdminUserId(Long.parseLong(json.get("adminUserId")));
    }
    if (!json.get("broadleafCurrency").equals("null")) {
        context.setBroadleafCurrency(em.find(BroadleafCurrencyImpl.class, json.get("broadleafCurrency")));
    }
    if (!json.get("currentCatalog").equals("null")) {
        context.setCurrentCatalog(em.find(CatalogImpl.class, Long.parseLong(json.get("currentCatalog"))));
    }
    if (!json.get("currentProfile").equals("null")) {
        context.setCurrentProfile(em.find(SiteImpl.class, Long.parseLong(json.get("currentProfile"))));
    }
    if (!json.get("deployBehavior").equals("null")) {
        context.setDeployBehavior(DeployBehavior.valueOf(json.get("deployBehavior")));
    }
    if (!json.get("deployState").equals("null")) {
        context.setDeployState(DeployState.valueOf(json.get("deployState")));
    }
    if (!json.get("internalIgnoreFilters").equals("null")) {
        context.setInternalIgnoreFilters(Boolean.valueOf(json.get("internalIgnoreFilters")));
    }
    if (!json.get("locale").equals("null")) {
        context.setLocale(em.find(LocaleImpl.class, json.get("locale")));
    }
    if (!json.get("validateProductionChangesState").equals("null")) {
        context.setValidateProductionChangesState(ValidateProductionChangesState.valueOf(json.get("validateProductionChangesState")));
    }
    if (!json.get("timeZone").equals("null")) {
        context.setTimeZone(TimeZone.getTimeZone(json.get("timeZone")));
    }
    return context;
}
Also used : HashMap(java.util.HashMap) CatalogImpl(org.broadleafcommerce.common.site.domain.CatalogImpl) JsonFactory(com.fasterxml.jackson.core.JsonFactory) IOException(java.io.IOException) LocaleImpl(org.broadleafcommerce.common.locale.domain.LocaleImpl) SiteImpl(org.broadleafcommerce.common.site.domain.SiteImpl) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SandBoxImpl(org.broadleafcommerce.common.sandbox.domain.SandBoxImpl) BroadleafCurrencyImpl(org.broadleafcommerce.common.currency.domain.BroadleafCurrencyImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 50 with JsonFactory

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonFactory in project calcite by apache.

the class DruidQueryFilterTest method testInFilter.

@Test
public void testInFilter() throws IOException {
    final Fixture f = new Fixture();
    final List<? extends RexNode> listRexNodes = ImmutableList.of(f.rexBuilder.makeInputRef(f.varcharRowType, 0), f.rexBuilder.makeExactLiteral(BigDecimal.valueOf(1)), f.rexBuilder.makeExactLiteral(BigDecimal.valueOf(5)), f.rexBuilder.makeLiteral("value1"));
    RexNode inRexNode = f.rexBuilder.makeCall(SqlStdOperatorTable.IN, listRexNodes);
    DruidJsonFilter returnValue = DruidJsonFilter.toDruidFilters(inRexNode, f.varcharRowType, druidQuery);
    Assert.assertNotNull("Filter is null", returnValue);
    JsonFactory jsonFactory = new JsonFactory();
    final StringWriter sw = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createGenerator(sw);
    returnValue.write(jsonGenerator);
    jsonGenerator.close();
    Assert.assertThat(sw.toString(), is("{\"type\":\"in\",\"dimension\":\"dimensionName\"," + "\"values\":[\"1\",\"5\",\"value1\"]}"));
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)266 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)102 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)91 JsonParser (com.fasterxml.jackson.core.JsonParser)78 Test (org.junit.Test)65 IOException (java.io.IOException)62 StringWriter (java.io.StringWriter)60 Map (java.util.Map)27 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)25 JsonNode (com.fasterxml.jackson.databind.JsonNode)21 List (java.util.List)18 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)16 JsonToken (com.fasterxml.jackson.core.JsonToken)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 File (java.io.File)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 InputStreamReader (java.io.InputStreamReader)9 TypeReference (com.fasterxml.jackson.core.type.TypeReference)8 SimpleParseUUT (com.instagram.common.json.annotation.processor.uut.SimpleParseUUT)8