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


Java JsonNodeFactory類代碼示例

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


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

示例1: apply

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
/**
 * Applies this schema rule to take the required code generation steps.
 * <p>
 * For each property present within the properties node, this rule will
 * invoke the 'property' rule provided by the given schema mapper.
 *
 * @param nodeName
 *            the name of the node for which properties are being added
 * @param node
 *            the properties node, containing property names and their
 *            definition
 * @param jclass
 *            the Java type which will have the given properties added
 * @return the given jclass
 */
@Override
public JDefinedClass apply(String nodeName, JsonNode node, JDefinedClass jclass, Schema schema) {
    if (node == null) {
        node = JsonNodeFactory.instance.objectNode();
    }

    for (Iterator<String> properties = node.fieldNames(); properties.hasNext(); ) {
        String property = properties.next();

        ruleFactory.getPropertyRule().apply(property, node.get(property), jclass, schema);
    }

    if (ruleFactory.getGenerationConfig().isGenerateBuilders() && !jclass._extends().name().equals("Object")) {
        addOverrideBuilders(jclass, jclass.owner()._getClass(jclass._extends().fullName()));
    }

    ruleFactory.getAnnotator().propertyOrder(jclass, node);

    return jclass;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:36,代碼來源:PropertiesRule.java

示例2: toConnectData

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
@Override
public SchemaAndValue toConnectData(String topic, byte[] value) {
    JsonNode jsonValue;
    try {
        jsonValue = deserializer.deserialize(topic, value);
    } catch (SerializationException e) {
        throw new DataException("Converting byte[] to Kafka Connect data failed due to serialization error: ", e);
    }

    if (enableSchemas && (jsonValue == null || !jsonValue.isObject() || jsonValue.size() != 2 || !jsonValue.has("schema") || !jsonValue.has("payload")))
        throw new DataException("JsonConverter with schemas.enable requires \"schema\" and \"payload\" fields and may not contain additional fields." +
                " If you are trying to deserialize plain JSON data, set schemas.enable=false in your converter configuration.");

    // The deserialized data should either be an envelope object containing the schema and the payload or the schema
    // was stripped during serialization and we need to fill in an all-encompassing schema.
    if (!enableSchemas) {
        ObjectNode envelope = JsonNodeFactory.instance.objectNode();
        envelope.set("schema", null);
        envelope.set("payload", jsonValue);
        jsonValue = envelope;
    }

    return jsonToConnect(jsonValue);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:25,代碼來源:JsonConverter.java

示例3: main

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
public static void main(String[] args) {
	GlbToB3dmConvertor convertor = new GlbToB3dmConvertor();
	JsonNodeFactory factory = new JsonNodeFactory(false);
	try {
		ObjectNode featureTableJsonNode = factory.objectNode();
		featureTableJsonNode.put("BATCH_LENGTH", 0);
		ByteBuffer glbBuffer = convertor.getBufferFromUri("", new File("D:\\tttt.glb").toPath());
		ByteBuffer b3dmBuffer = convertor.glbToB3dm(glbBuffer, featureTableJsonNode);
		OutputStream os = new FileOutputStream(new File("D:\\tttt.b3dm"));
		os.write(b3dmBuffer.array());
		os.flush();
		os.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
	
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:18,代碼來源:GlbToB3dmConvertor.java

示例4: makeInputValues

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
@Override
public Map<PortName, BrickValue> makeInputValues() {
    JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
    ObjectMapper mapper = new ObjectMapper();

    List<JsonNode> compareSessionJson = new ArrayList<>();
    JsonNode sessionNode = mapper.valueToTree(compareSession);
    BrickValue sessionBrickValue = new BrickValue(new BrickDataType("BrowserSessionRef"), sessionNode);
    compareSessionJson.add(mapper.valueToTree(sessionBrickValue));

    return ImmutableMap.of(
            new PortName("referenceSession"), new BrickValue(new BrickDataType("BrowserSessionRef"), jsonNodeFactory.textNode(referenceSession.getValueAsString())),
            new PortName("compareSession"), new BrickValue(new BrickDataType("BrowserSessionRef"), jsonNodeFactory.textNode(compareSession.getValueAsString())),
            new PortName("matchingType"), new BrickValue(new BrickDataType("String"), jsonNodeFactory.textNode("tag")),
            new PortName("enabledynamicelementsfilter"), new BrickValue(new BrickDataType("Boolean"), jsonNodeFactory.booleanNode(true))
    );
}
 
開發者ID:webmate-io,項目名稱:webmate-sdk-java,代碼行數:18,代碼來源:BrowserSessionRegressionJobInput.java

示例5: exportStatus

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
public boolean exportStatus(String outputFile) {
    Repository frozenRepository = this.repository.getSnapshotTo(this.repository.getRoot());

    File dumpFile = new File(outputFile);

    try(FileWriter fw = new FileWriter(dumpFile.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw)) {
        JsonNodeFactory jsonFactory = new JsonNodeFactory(false);
        ObjectNode mainNode = jsonFactory.objectNode();
        for (ByteArrayWrapper address : frozenRepository.getAccountsKeys()) {
            if(!address.equals(new ByteArrayWrapper(ZERO_BYTE_ARRAY))) {
                mainNode.set(Hex.toHexString(address.getData()), createAccountNode(mainNode, address.getData(), frozenRepository));
            }
        }
        ObjectMapper mapper = new ObjectMapper();
        ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
        bw.write(writer.writeValueAsString(mainNode));
        return true;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        panicProcessor.panic("dumpstate", e.getMessage());
        return false;
    }
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:24,代碼來源:NetworkStateExporter.java

示例6: mapToJsonNonStringKeys

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
@Test
public void mapToJsonNonStringKeys() {
    Schema intIntMap = SchemaBuilder.map(Schema.INT32_SCHEMA, Schema.INT32_SCHEMA).build();
    Map<Integer, Integer> input = new HashMap<>();
    input.put(1, 12);
    input.put(2, 15);
    JsonNode converted = parse(converter.fromConnectData(TOPIC, intIntMap, input));
    validateEnvelope(converted);
    assertEquals(parse("{ \"type\": \"map\", \"keys\": { \"type\" : \"int32\", \"optional\": false }, \"values\": { \"type\" : \"int32\", \"optional\": false }, \"optional\": false }"),
            converted.get(JsonSchema.ENVELOPE_SCHEMA_FIELD_NAME));

    assertTrue(converted.get(JsonSchema.ENVELOPE_PAYLOAD_FIELD_NAME).isArray());
    ArrayNode payload = (ArrayNode) converted.get(JsonSchema.ENVELOPE_PAYLOAD_FIELD_NAME);
    assertEquals(2, payload.size());
    Set<JsonNode> payloadEntries = new HashSet<>();
    for (JsonNode elem : payload)
        payloadEntries.add(elem);
    assertEquals(new HashSet<>(Arrays.asList(JsonNodeFactory.instance.arrayNode().add(1).add(12),
                    JsonNodeFactory.instance.arrayNode().add(2).add(15))),
            payloadEntries
    );
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:23,代碼來源:JsonConverterTest.java

示例7: write

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
@Override
public JsonNode write( final Object obj ) throws IOException{
  ArrayNode array = new ArrayNode( JsonNodeFactory.instance );
  if( ! ( obj instanceof List ) ){
    return array;
  }

  List<Object> listObj = (List)obj;
  for( Object childObj : listObj ){
    if( childObj instanceof List ){
      array.add( JacksonContainerToJsonObject.getFromList( (List<Object>)childObj ) );
    }
    else if( childObj instanceof Map ){
      array.add( JacksonContainerToJsonObject.getFromMap( (Map<Object,Object>)childObj ) );
    }
    else{
      array.add( ObjectToJsonNode.get( childObj ) );
    }
  }

  return array;
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:23,代碼來源:JacksonArrayFormatter.java

示例8: writeParser

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
@Override
public JsonNode writeParser( final IParser parser ) throws IOException{
  ArrayNode array = new ArrayNode( JsonNodeFactory.instance );
  for( int i = 0 ; i < parser.size() ; i++ ){
    IParser childParser = parser.getParser( i );
    if( childParser.isMap() || childParser.isStruct() ){
      array.add( JacksonParserToJsonObject.getFromObjectParser( childParser ) );
    }
    else if( childParser.isArray() ){
      array.add( JacksonParserToJsonObject.getFromArrayParser( childParser ) );
    }
    else{
      array.add( PrimitiveObjectToJsonNode.get( parser.get( i ) ) );
    }
  }
  return array;
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:18,代碼來源:JacksonArrayFormatter.java

示例9: write

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
@Override
public JsonNode write( final Object obj ) throws IOException{
  ObjectNode objectNode = new ObjectNode( JsonNodeFactory.instance );
  if( ! ( obj instanceof Map ) ){
    return objectNode;
  }

  Map<Object,Object> mapObj = (Map<Object,Object>)obj;
  for( Map.Entry<Object,Object> entry : mapObj.entrySet() ){
    String key = entry.getKey().toString();
    Object childObj = entry.getValue();
    if( childObj instanceof List ){
      objectNode.put( key , JacksonContainerToJsonObject.getFromList( (List<Object>)childObj ) );
    }
    else if( childObj instanceof Map ){
      objectNode.put( key , JacksonContainerToJsonObject.getFromMap( (Map<Object,Object>)childObj ) );
    }
    else{
      objectNode.put( key , ObjectToJsonNode.get( childObj ) );
    }
  }

  return objectNode;
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:25,代碼來源:JacksonObjectFormatter.java

示例10: writeParser

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
@Override
public JsonNode writeParser( final IParser parser ) throws IOException{
  ObjectNode objectNode = new ObjectNode( JsonNodeFactory.instance );
  for( String key : parser.getAllKey() ){
    IParser childParser = parser.getParser( key );
    if( childParser.isMap() || childParser.isStruct() ){
      objectNode.put( key , JacksonParserToJsonObject.getFromObjectParser( childParser ) );
    }
    else if( childParser.isArray() ){
      objectNode.put( key , JacksonParserToJsonObject.getFromArrayParser( childParser ) );
    }
    else{
      objectNode.put( key , PrimitiveObjectToJsonNode.get( parser.get( key ) ) );
    }
  }
  return objectNode;
}
 
開發者ID:yahoojapan,項目名稱:dataplatform-schema-lib,代碼行數:18,代碼來源:JacksonObjectFormatter.java

示例11: asJson

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
private ArrayNode asJson(List<User> users) {
    ArrayNode array = JsonNodeFactory.instance.arrayNode();
    for (User u : users) {
        String name = String.format("%s %s", u.getFirstName(), u.getLastName());
        if (u.getUserIdentifier() != null) {
            name += String.format(" (%s)", u.getUserIdentifier());
        }
        ObjectNode part = Json.newObject();
        part.put("id", u.getId());
        part.put("firstName", u.getFirstName());
        part.put("lastName", u.getLastName());
        part.put("userIdentifier", u.getUserIdentifier());
        part.put("name", name);
        array.add(part);
    }
    return array;
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:18,代碼來源:ReservationController.java

示例12: addSpeaker

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
/**
 * Adds BGP speaker to configuration.
 *
 * @param speaker BGP speaker configuration entry
 */
public void addSpeaker(BgpSpeakerConfig speaker) {
    ObjectNode speakerNode = JsonNodeFactory.instance.objectNode();

    speakerNode.put(NAME, speaker.name().get());

    speakerNode.put(VLAN, speaker.vlan().toString());

    speakerNode.put(CONNECT_POINT, speaker.connectPoint().elementId().toString()
            + "/" + speaker.connectPoint().port().toString());

    ArrayNode peersNode = speakerNode.putArray(PEERS);
    for (IpAddress peerAddress: speaker.peers()) {
        peersNode.add(peerAddress.toString());
    }

    ArrayNode speakersArray = bgpSpeakers().isEmpty() ?
            initBgpConfiguration() : (ArrayNode) object.get(SPEAKERS);
    speakersArray.add(speakerNode);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:25,代碼來源:BgpConfig.java

示例13: syncDrafts_WithValidCustomFieldsChange_ShouldSyncIt

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
@Test
public void syncDrafts_WithValidCustomFieldsChange_ShouldSyncIt() {
    final List<CategoryDraft> newCategoryDrafts = new ArrayList<>();

    final Map<String, JsonNode> customFieldsJsons = new HashMap<>();
    customFieldsJsons.put(BOOLEAN_CUSTOM_FIELD_NAME, JsonNodeFactory.instance.booleanNode(false));
    customFieldsJsons
        .put(LOCALISED_STRING_CUSTOM_FIELD_NAME, JsonNodeFactory.instance.objectNode()
                                                                         .put("de", "rot")
                                                                         .put("en", "red")
                                                                         .put("it", "rosso"));

    final CategoryDraft categoryDraft1 = CategoryDraftBuilder
        .of(LocalizedString.of(Locale.ENGLISH, "Modern Furniture"),
            LocalizedString.of(Locale.ENGLISH, "modern-furniture"))
        .key(oldCategoryKey)
        .custom(CustomFieldsDraft.ofTypeIdAndJson(OLD_CATEGORY_CUSTOM_TYPE_KEY, customFieldsJsons))
        .build();

    newCategoryDrafts.add(categoryDraft1);

    final CategorySyncStatistics syncStatistics = categorySync.sync(newCategoryDrafts).toCompletableFuture().join();

    assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
}
 
開發者ID:commercetools,項目名稱:commercetools-sync-java,代碼行數:26,代碼來源:CategorySyncIT.java

示例14: resolveAttributeReference_WithProductReferenceAttribute_ShouldResolveAttribute

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
@Test
public void resolveAttributeReference_WithProductReferenceAttribute_ShouldResolveAttribute() {
    when(productService.fetchCachedProductId(anyString()))
        .thenReturn(CompletableFuture.completedFuture(Optional.empty()));

    final ObjectNode attributeValue = JsonNodeFactory.instance.objectNode();
    attributeValue.put("typeId", "product");
    attributeValue.put("id", "nonExistingProductKey");
    final AttributeDraft productReferenceAttribute = AttributeDraft.of("attributeName", attributeValue);

    final AttributeDraft resolvedAttributeDraft =
        referenceResolver.resolveAttributeReference(productReferenceAttribute)
                         .toCompletableFuture().join();
    assertThat(resolvedAttributeDraft).isNotNull();
    assertThat(resolvedAttributeDraft).isSameAs(productReferenceAttribute);
}
 
開發者ID:commercetools,項目名稱:commercetools-sync-java,代碼行數:17,代碼來源:VariantReferenceResolverTest.java

示例15: resolveAttributeReference_WithEmptyReferenceSetAttribute_ShouldNotResolveReferences

import com.fasterxml.jackson.databind.node.JsonNodeFactory; //導入依賴的package包/類
@Test
public void resolveAttributeReference_WithEmptyReferenceSetAttribute_ShouldNotResolveReferences() {
    final ArrayNode referenceSet = JsonNodeFactory.instance.arrayNode();

    final AttributeDraft productReferenceAttribute = AttributeDraft.of("attributeName", referenceSet);

    final AttributeDraft resolvedAttributeDraft =
        referenceResolver.resolveAttributeReference(productReferenceAttribute)
                         .toCompletableFuture().join();
    assertThat(resolvedAttributeDraft).isNotNull();
    assertThat(resolvedAttributeDraft.getValue()).isNotNull();

    final Spliterator<JsonNode> attributeReferencesIterator = resolvedAttributeDraft.getValue().spliterator();
    assertThat(attributeReferencesIterator).isNotNull();
    final Set<JsonNode> resolvedSet = StreamSupport.stream(attributeReferencesIterator, false)
                                                   .collect(Collectors.toSet());
    assertThat(resolvedSet).isEmpty();
}
 
開發者ID:commercetools,項目名稱:commercetools-sync-java,代碼行數:19,代碼來源:VariantReferenceResolverTest.java


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