本文整理匯總了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;
}
示例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);
}
示例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();
}
}
示例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))
);
}
示例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;
}
}
示例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
);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}