当前位置: 首页>>代码示例>>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;未经允许,请勿转载。